Excel - Summary count of multi-column duplicates - excel

I can't seem to wrap my head around an answer for this. I can find duplicates when using a formula that looks at a single sell and compare it to a range of cells, and copy that formula down every row; afterward I can just sum the results. However, I want a single formula in a single cell.
I want to take a range of cells in one column, compare that entire set to a range of cells in another column, and sum all duplicate cells where the cell in column 1 matches a cell in column 2. For this exercise, all cells in each column are unique within that column, they are only potentially duplicate between columns.
For example:
C1 C2
R1 1 2
R2 2 6
R3 3 7
R4 4 1
R5 5 8
I want a single column sum with a result of 2 (the duplicate cells in C1 is 1 and 2).
This will ultimately be converted into a VBA script however I can work with starting with a single formula. If starting out at VBA is easier then that works for me too.
My specific question is: which functions in excel do I use to accomplish this task?
Thanks for your help.

I believe the formula you want in cell C3 is:
=IF(ISERROR(VLOOKUP(A1,$B$1:$B$5,1,FALSE)),0,1)
This will return a 1 if your column-1 value appears in column 2, and a 0 if it doesn't. Then you can simply copy it down for the extent of your data (changing the referenced range as needed) sum the results of column 3. (Note that the FALSE is important as it forces exact matches; otherwise, Excel will display approximate matches, which will compromise the accuracy of your results.)

Related

Excel Auto number row based on criteria

I'm trying to create a spreadsheet in excel which creates a sequential number in a column (B) depending on the contents of another column. Currently, there are two possibilities of what could be in Column A ("BI" or "GF"). So I want the data to look like this
COL A COLB
BI 1
BI 2
GF 1
BI 3
GF 2
GF 3
BI 4
BI 5
I've tried several attempts to do this but can't seem to find a solution. Any help would be greatly appreciated.
In B2, try this formula:
=CountIf(A$2:A2,A2)
Try to use the offset equation.
The first cell in COL B will look similar to this:
=COUNTIFS(OFFSET(A$1$1:A1,0,0),A1)
The second should look like this:
=COUNTIFS(OFFSET(A$1$1:A2,0,0),A2)
Drag this down in Col B as far as desired. If you are using a table this should autofill.
Explanation:
Essentially you are using the OFFSET formula to create a dynamic range.
The A$1$ serves as the start of your range by making this an absolute reference and the A1 will serve as the end of your range.
By making the ending cell a relative reference, the array the COUNTIFS function search will never go beyond the row the of the cell the formula is relative of.
In your example, the formula in the first row in Col B would result in 1. The reason is the OFFSET returns the array of A$1$:A1 and the COUNTIFS searches through that array and returns a count of all cells equal to A1 which is "BI".
The second row retains the original starting cell for the array of A$1$ however the end of the array is A2. So the COUNTIFS function sees the new array to search through to be A$1$:A2. The COUNTIFS then searchs through each cell equal to A2 which like A1 is "BI". There are two cells equal to "BI" in the new array and thus the reult is 2.
How this works like you want is displayed in the third row of Col B.
The OFFSET functions simply expands the array size to A$1$:A3. The COUNTIFS will work as it normally does, it takes the array, called the criteriarange in Excel, and performs a count for all items that equal A3. A3 in this case is equal to "GF" and in the array A$1$:A3 there are two cells equal to "BF" and one equal to "GF".
Hope this helps!

Combining data in excel

Dears,
I have 4 columns in excel.
Each row have two values but also it is mapped to another row.
I'd like to sum the values from these the rows that are mapped and delete the extra rows.
Example attached: Row A has two values but also mapped to Row C. I want to add the values in Row A with the ones in Row C and keep Row A and delete Row C
Is it possible to use formulas instead of VBA as I don't have experience in VBA?
Please advise.
Assuming your Keyword data starts with A2 and Value 1 starts with B2 and Value 2 starts with C2. (Please refer the snap below)
Apply the below formula in H2 for Value 1 summing and drag down
=IF(VLOOKUP(G2,$A$2:$D$4,4,FALSE)=0,VLOOKUP(G2,$A$2:$D$4,2,FALSE),VLOOKUP(G2,$A$2:$D$4,2,FALSE)+VLOOKUP(VLOOKUP(G2,$A$2:$D$4,4,FALSE),$A$2:$D$4,2,FALSE))
Apply the below formula in I2 for Value 2 summing and drag down
=IF(VLOOKUP(G2,$A$2:$D$4,4,FALSE)=0,VLOOKUP(G2,$A$2:$D$4,3,FALSE),VLOOKUP(G2,$A$2:$D$4,3,FALSE)+VLOOKUP(VLOOKUP(G2,$A$2:$D$4,4,FALSE),$A$2:$D$4,3,FALSE))
EDIT #1 If G value does not contain in Table 1 then apply the below formula
in H2
=IF(ISERROR(IF(VLOOKUP(G2,$A$2:$D$4,4,FALSE)=0,VLOOKUP(G2,$A$2:$D$4,2,FALSE),VLOOKUP(G2,$A$2:$D$4,2,FALSE)+VLOOKUP(VLOOKUP(G2,$A$2:$D$4,4,FALSE),$A$2:$D$4,2,FALSE))),"Not Found in Table",IF(VLOOKUP(G2,$A$2:$D$4,4,FALSE)=0,VLOOKUP(G2,$A$2:$D$4,2,FALSE),VLOOKUP(G2,$A$2:$D$4,2,FALSE)+VLOOKUP(VLOOKUP(G2,$A$2:$D$4,4,FALSE),$A$2:$D$4,2,FALSE)))
in I2
=IF(ISERROR(IF(VLOOKUP(G2,$A$2:$D$4,4,FALSE)=0,VLOOKUP(G2,$A$2:$D$4,3,FALSE),VLOOKUP(G2,$A$2:$D$4,3,FALSE)+VLOOKUP(VLOOKUP(G2,$A$2:$D$4,4,FALSE),$A$2:$D$4,3,FALSE))),"Not Found in Table",IF(VLOOKUP(G2,$A$2:$D$4,4,FALSE)=0,VLOOKUP(G2,$A$2:$D$4,3,FALSE),VLOOKUP(G2,$A$2:$D$4,3,FALSE)+VLOOKUP(VLOOKUP(G2,$A$2:$D$4,4,FALSE),$A$2:$D$4,3,FALSE)))

Adding all the values below the current cell in Excel

I am trying to display the total sum of all the numbers for a particular column. I want the sum to be displayed above the column as follows:
21 30
A B
6 5
6 10
6 10
3 5
I know I can sum the values and display it at the bottom of the column using =SUM(A3:INDIRECT("D"&ROW()-2)), however I am not getting a way to display it at the top of the column.
Please guide.
Based on the comments and the previous answers I suggest following formula, entered in cell A1:
=SUM(OFFSET(A$2,0,0,ROWS(b:b)-1))
You can then copy/paste to the right till second last column.
You could also modify your formula in A1 like this to achieve the same:
=SUM(INDIRECT("A2:A"&ROWS(A:A)-2))
But then you cannot copy/paste to the right...
A more general approach with your idea would be:
=SUM(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROWS(A:A),COLUMN())))
You can then copy/paste to the right till last column.
Some explanations:
Both formula sums up every value in the range from A2 till the bottom of column A (i.e. for Excel 2010 this would be A2:A1048576)
It doesn't matter if there are blanks or cells without value; the formula sums up only the numbers
I put A$2 and B:B in the OFFSET formula to avoid circular references, since I'm writing in cell A1 and I cannot write A$1 nor A:A
With the INDIRECT formula you don't have to worry about circular references
Further commenting (sorry, I don't have the credits to comment at the right place under the question):
Phylogenesis formula =SUM(A3:A65535) could also do the work, isn't it?
Didn't understand your question at first, because you talk of "sum of all the numbers for a particular row" but then you sum columns, isn't it?
When I'm doing something like this, I prefer to not include any empty cells beneath the range I'm summing, because I've had errors in the past as the result of including them (usually because there's a cell way down in the column somewhere that I'm not expecting to have a value). I'm assuming that A & B are your column headers. Assuming that, here is how I would do it. This is your formula for cell A1:
=SUM(OFFSET(A$1,2,0,COUNTA(A$3:A$65535)))
Explanation
I'm updating this with a brief explanation, per the OP's request.
According to ExcelFunctions.net:
The Excel Offset function returns range of cells that is a specified number of rows and columns from an initial supplied range.
The function reference for OFFSET is:
=OFFSET(reference, rows, cols, [height], [width])
What this formula does is create a dynamic range based on the number of cells in the selection, relative to cell A$1. This is an offset of two rows and no columns, which starts the range at A$3. The height of the range is the total number of filled cells in the range A$3:A$65535. The assumption here is that there are no blank cells in the range, which there were not in the sample data.

Set condition before running Vlookup VBA

I created a Vlookup but first want a condition to be met to determine what Vlookup to use.
Such as
If cell = 1 then
run Vlookup #1
If cell = 2 then
run Vlookup #2
There are only 4 possible variables that the cell could equal. This would have to be on a loop, because the entries in the worksheet are multiple. It would first see what the specific cell equaled, then determine what Vlookup to use.
Any insight?
I doubt you need a loop because this might be handled within the VLOOKUP, though I am assuming the conditional cell (one of four values) is not the trigger cell for the VLOOKUP:
Here A1 is the condition, C1 the trigger value and D1 contains the formula for the lookup:
=VLOOKUP(C1,$H$1:$L$3,A1+1,0)
and hence also the result k in the example.
A2 merely determines how many columns across to step when looking for the appropriate value in the lookup table (here in the box).
We know from ColumnH that 20 is in the second row of the table and A1+1 says take the value A1 (ie four) columns further to the right.
Change the blue to 2 and the yellow to 30, for example, and the result is f.
If values are for sure integers 1 to N, just like #Tim pointed out you can use CHOOSE:
=CHOOSE(A1;Vlookup1;Vlookup2;...;VlookupN)
If A1=1 Vlookup1 will be executed, A1=2 Vlookup2....A1=N... VlookupN

Using SumIf to add cells instead of range of values

I currently have a situation wherein I am required to subtract 2 cells. 1 cell is already known but the second cell is to be found from a range. I have seen this can be done using the SumIf but among the range,criteria,sum_range factor, I dont know how to mention the sum_range as 2 distinct cells.
Also, point to be noted is that these 2 cells needed to be subtracted are in 2 different sheets in the same excel workbook.
I was trying using this below
=sumif(AC1:AC3,Sheet1!AA14,Sheet2!S1 - Sheet1!S14)
But it gives error. Can someone help. Am trying to match Sheet1!AA14 with any one of the values in this range AC1:AC3. And for the a perfect match, it would subtract the corresponding sheets "S" cells
please help
I suggest you try using VLOOKUP if you have the first value of your subtraction equation. Here is an example (sorry I don't understand your setup enough to use your cell numbers):
A B C D
test 20 15 test
test1 10
=VLOOKUP(D1,A1:B2,2) - C1 ' results in 5 (20 - 15)
Look for value in D1
A1:B2 is the range with the value and the data you want back. 1st column is the search column.
If it finds the value it will give back the value in the 2nd column of the range, in this case B.
You then take the value and subtract the value in C1 from it.
Check out MS's documentation on VLOOKUP and mess around with it. Best of luck.

Resources