Excel - Tell if Column A a third of Column B - excel-formula

I'm drawing a blank how to do what I think is a simple formula with a color change.
I have two columns see below
A | B
------
3 | 9
25| 10
I want to change the value in Column A is a third of Column B so the first row the 3 should be highlighted in red where as the second row just be left alone. I have tried MOD, IF statements to keep it simple but just tripping over myself.
Any pointers to functions or a start of a formula at a high level like IF(column b / column a) will lead me to my answer be appreciated.
Thank you for your time.

Related

Excel highlight duplicates in 2 columns, ignoring same row

I have 2 non adjacent text columns that I wish to compare. There may be duplicates in both columns but if they are not on the same row I need them to be highlighted in both columns. In the example below, Barry and Larry would both be highlighted in Columns A & C.
| Col A. | Col B. | Col C.
Row1.| Harry | London | Harry
Row2.| Barry | Paris | Larry
Row3.| Larry | New York | Barry
Row4.| Gary | Munich | Tom
If the same names are not aligned in the same row I would then cut and paste the offenders to resolve the problem. In this case the Barry in column C would be cut and inserted into row 2, forcing Larry down into row 3. Nothing would then be highlighted.
I guess it is a conditional formatting problem but I can't get a formula to work. I would appreciate some ideas.
So if I am understanding you correctly, you want to:
1) Find duplicates and highlight them
2) Move the offenders
Is there some reason this needs to be two parts? For moving the offenders I would run 2 loops, one to loop through the cells in column A, for each cell in column A I would loop through column C until I find the match, cut it, and paste it into the range that is two columns over from the current cell you are comparing in the first loop. you can use a range offset to find the right place to paste the name in column C.
Arrays would do this more quickly, so if you have a large number of records it would be worth looking in to.
You can use a dictionary object to accomplish both steps more easily, you can use dict.exists(value) to determine if a match exists and use those addresses for formatting, a quick google will help you with how to use them.
Honestly this seems like a homework problems so that's as far as I will go.

Formatting so that cell is colored differently if it matches any value in column A, or column B, or both?

I have tried solving this myself for some time and it just isn't working for me. It's a somewhat specific goal I have so I haven't had much success finding examples online, so I'm hoping for some direction on how best to approach this. I'm hoping to find a solution that uses VBA. I'm pretty new to VBA so bear with me please!
I am dealing with conditional background coloring based on matching cell values. I have three variable-length columns: A, B and D. Columns A and B are randomly selected subsets of the values that are in column D - so, the values in the different columns may match, but they probably won't be on the same row.
When a cell's value in column D matches that of a cell in column A, I want that cell's row from column D to column K to be colored blue. Likewise, if the cell's value in column D matches a value in column B, I would like it colored red. If a cell in column D matches a cell in both column A and B, I would like it colored purple.
Does that make sense? How would you suggest I approach this?
Let me know if I need to clarify further. I would greatly appreciate any help!
Using Excel 2013.
I have not actually seen your file, since I am at work, but I guess your table looks like this:
| A | B | C | D |
| 1 | 3 | | 1 |
| 3 | 5 | | 2 |
| 2 | 4 | | 3 |
| | | | 4 |
| | | | 5 |
I rather like simple formula based approaches for that, but I could give you a vba example too.
With this setup I propose to use VLOOKUP. You basically check, if the value is part of A, part of B and then you can do the rest with your conditional formatting.
So if additional columns are no problem, just use the lookup to generate a true or false answer (I apologise for formula mistakes, since I use a german excel version):
=NOT(ISERROR(VLOOKUP(D1,A:A,1,False)))
This will tell you TRUE, if there is a value in ALL of column A, that is equal to D1. If you also use this formula for column B you can base your colorcoding for blue and red on these two.
For the purple color you just need to compare the other two results again with a simple AND
Hope that is clear enough and I have read your question right.
Kaz

Conditional subtraction from multiple cells

A |B |C |....|K |L |M |
Tom |0 | |....|Tom |Jim |Dave |
Jim |1000 | |....|15000|14000|12000|
Dave |3000 | |....| | | |
Using Google Sheets for this one. I would like the values in columns K, L, and M to read from column B, detect if the corresponding cell from A reads one of 'Tom', 'Jim', or 'Dave' for example, and then subtract the amount from the correct column to reduce a running total. I've had some trouble figuring it out and tried to use conditional formatting to solve it but can't seem to quite get there. Is there a formula I can use that will read column B and subtract the amount shown from the correct column based on the name in column A?
So to pseudo-code it:
read(column B cell);
if(column B cell - 1 column = "Tom")
{
column K - (value of column B cell)
}
else if(column B cell - 1 column = "Jim")
{
column L - (value of column B cell)
}
etc.
Is there a simple method I can use to generate this result? Also thought about changing the formatting of a cell based on the name in the cell next to it and subtracting the value of any cell with that colour but this becomes unwieldy if names are added. Any assistance would be greatly appreciated!
would there be a way to constrain the formula to a single cell so I can have the total in a single location rather than down the columns? My plan is to have the total boxes scroll with the sheet and always be visible.
Let's assume that Columns A and B continue on down the sheet, with further name + amount entries. You want to have a single row of balances for each of the people.
The balance is then some initial value less the sum of amounts for that person. Say the amounts you've shown in row 2 are the initial values; here's how you could have row 3 reflect the remaining balance for each person (This is for "Tom", copy for the others):
=K2-sumif($A$2:$B,"="&K$1,$B$2:$B)
Alternative solution
This doesn't do exactly what you want, but it is more appropriate for a running total scenario, so others may find it useful to adapt to ledgers, etc.
The IF() function can be used to decide whether or not a value in Column B applies to one of the "total" columns, K to M.
Use this formula in K3, copy to the rest of the range:
=K2-if($A2=K$1,$B2,0)
This example is in Google Sheets, but the same formula works in Excel and other "compatible" offerings.
What you do is put the formula in each column.
Column K subtracts value of column B if column A = "Tom"
Column L subtracts value of column B if column A = "Jim"
etc

Excel function for comparing columns with repeated values

I'm using excel and have two columns (A & B) with values
I want to search for each value in Column A and return the position in Column B.
I'm using this formula:
IFERROR(MATCH("Values in Column A";"Array = Column B";0);0)
The results are:
Column A | Column B | Column C
1 | 4 | 2
2 | 1 | 3
3 | 2 | 4
4 | 1 | 1
1 | 2 | 2
| 3 |
It works fine if it doesn't encounter repeated values. However, I want it to encounter repeated values, so the formula should ignore the ones it was encountered before and go through the others. So the correct result should look like this:
Column C
2
3
5
1
4
Can you help me on this? Is there a VBA routine for this?
From the article Getting the 2nd matching value from a list using VLOOKUP formula, you can create a helper column to affix the instance number of each value, to create unique id's.
For example, in Column C, add the following function:
=A1&"-"&COUNTIF($A$1:A1,A1)
Note: The relative reference on the count range will cause the applicable range to grow as it is dragged down. The count of the items matching that cell in a range containing only that cell should always be one. As it gets dragged down to include other cells, it will increment accordingly.
Then add the same thing in Column D to get the instances of cells in Column B:
=B1&"-"&COUNTIF($B$1:B1,B1)
Finally, do the math you want to do in Column E like this:
=IFERROR(MATCH(C1,D:D,0),0)

Add cell string to another cell if 2 cells are the same for 2 rows

I'm trying to make a macro that will go through a spreadsheet, and based on the first and last name being the same for 2 rows, add the contents of an ethnicity column to the first row.
eg.
FirstN|LastN |Ethnicity |ID |
Sally |Smith |Caucasian |55555 |
Sally |Smith |Native American | |
Sally |Smith |Black/African American | |
(after the macro runs)
Sally |Smith |Caucasian/Native American/Black/African American|55555 |
Any suggestions on how to do this? I read several different methods for VBA but have gotten confused as to what way would work to create this macro.
EDIT
There may be more than 2 rows that need to be combined, and the lower row(s) need to be deleted or removed some how.
If you can use a formula, then you can do those:
Couple of assumptions I'm making:
Sally is in cell A2 (there are headers in row 1).
No person has more than 2 ethnicities.
Now, for the steps:
Put a filter and sort by name and surname. This provides for any person having their names separated. (i.e. if there is a 'Sally Smith' at the top, there are no more 'Sally Smith' somewhere down in the sheet after different people).
In column D, put the formula =if(and(A2=A3,B2=B3),C2&"/"&C3,"")
Extend the filter to column D and filter out all the blanks.
That is does is it sees whether the names cells A2 and A3 are equal (names are the same), and whether the cells B2 and B3 are equal (surnames are the same).
If both are true, it's the same person, so we concatenate (using & is another way to concatenate besides using concatenate()) the two ethnicities.
Otherwise, if either the name, or username, or both are different, leave as blank.
To delete the redundant rows altogether, copy/paste values on column D, filter on the blank cells in column D and delete. Sort afterwards.
EDIT: As per edit of question:
The new steps:
Put a filter and sort by name and surname. (already explained above)
In column E, put the formula =IF(AND(A1=A2,B1=B2),E1&"/"&C2,C2) (I changed the formula to adapt to the new method)
In column F, put the formula =if(and(A1=A2,B1=B2),F1+1,1)
In column G, put the formula =if(F3<F2,1,0)
In column H, put the formula =if(and(D2="",A1=A2,B1=B2),H1,D2) (this takes the ID wherever it goes).
Put the formulae as from row 2. What step 3 does is putting an incremental number for the people with same name.
What step 4 does is checking for when the column F goes back to 1. This will identify your 'final rows to be kept'.
Here's my output from those formulae:
The green rows are what you keep (notice that there is 1 in column G that allows you to quickly spot them), and the columns A, B, C, E and H are the columns you keep in the final sheet. Don't forget to copy/paste values once you are done with the formulae and before deleting rows!
If first Sally is in A1 then =IF(AND(A1=A2,B1=B2),C1&"/"&C2,"")copied down as appropriate might suit. Assumes where not the same a blank ("") is preferred to repetition of the C value.

Resources