Let's say I have 2 columns that I'm comparing data in. If both cells match I want both cells to turn green. If they don't match I want them to turn yellow. Is there a formula that will allow me to check this for multiple records, or would this require looping in VBA? I can only seem to make this work 1 record at a time using conditional formatting. Thanks!
Edit: Adding results from provided answer
You can use conditional formatting, but you'll have to format each of the two columns separately.
Say your data is in A2:B100 (for simplicity)
Select the cells in columnA (A2:A100)
Select conditional Formatting >> New Rule >> Use a formula...
Enter the formula "=A3<>B3", choose a format and click OK
Repeat on column B.
Related
I want to use a macro to filter columns in a table. I want to filter for values that are higher than a value I want to put in cell, to be able to easily change the filter. Does someone have a trick for doing this with vba?
Many thanks, Bram
Record a macro whilst filtering a table on a column value. You would right click on the table column header of interest whilst recording the code and select Number_Filters > Greater Than and enter your desired number. That would give you the outline code. You can then amend the code to pick up the desired value from a specified cell. If applying filter to multiple columns record macro whilst doing this process over several columns.
Thank you for you answer. I tried this already, but I could not get the macro to pick from a specific cell. If I stored the value of the specific cell under as 'value' and put that in the outlined code, it would just do Greater Than value.. DO you have shortcut for this?
Thanks!
I have a document with functionality via data validation selection. Each selection triggers a macro to hide certain rows. I have the following conditional formatting formula =MOD(ROW(),2)=1 and it works great when all rows are unhidden, however I'm looking for a more dynamic formula that can change when the rows are automatically hidden. I'm open to using VBA in lieu of conditional formatting.
You can use SUBTOTAL to count non-hidden rows. This relies on a column being filled (ie no blanks). I've used column A, use a different one if you need to.
Conditional Format formula
=MOD(SUBTOTAL(103,A1:$A$1),2)=1
can you tell me how I can group rows using a value in a specific cell and then highlight the individual groups by alternate colours i.e. one group with white background and one group with a colour in excel? I have macro code which inserts a blank line but I don't know how to colour using macro.
You don't need a macro, just run conditional formatting for values equal to the value of the group you are using.
Here is an excellent guide for how to highlight a row using conditional formatting. It does exactly what you asked for without having to write any code. As you can see it works for multiple rows sharing the common set value.
This is assuming that the only reason you wanted them grouped in the first place was for colouring them together, this method is best if you want to preserve the order of your data.
It's easy to do conditional formatting that compares 2 columns, e.g.: =$A1=$B1. But what if I also want to compare C and D, but NOT B and C? Ideally, I'd like to do this with a single conditional formatting formula since I have many columns, but I'll settle for VBA if necessary (I'm just unfamiliar with conditional formatting in VBA).
NOTE: I've tried some variations of =AND(MOD(COLUMN(),2),A1=B1), but that hasn't worked.
NOTE 2: Here's some more specifics: Basically I'm comparing data in two nearly identical tables, and I want to highlight any differences. So for example, each table has a "Study_ID" column, and I want to view those side by side on a new sheet, e.g. in Columns A and B, highlighting unmatched cells in both columns. It would be easy to say =$A1:$B1 and apply to =$A$A:$B$B. But I'm also viewing "Name" side by side, e.g. in Columns C and D. I could add a new formula =$C1:$D1. But since the source tables have like 20 columns, that would require like 20+ formulas. I'd prefer one.
Thanks!
The image below was accomplished using multiple formulas (=$A1<>$B1, applied to =$A$1:$B$4, and =$C1<>$D1, applied to =$C$1:$D$4)
Edit: Figured out a single formula that will do it:
=A2<>OFFSET(A2,,IF(MOD(COLUMN(),2)=1,1,-1))
I'm trying to get a msgbox when a value is duplicate base on 2 columns. The first column Value can be repeated but the second column will determine if it's a duplicate or not.
i.e.
Column B = Code,
Column L = Month
The user can enter the Code several times, but if he enters it on the same month I want the msgbox pop up
Is your intention to warn\inform the user? If so, I would do this without a macro. I would use conditional formatting to make the cell change color whenever the duplicate information is entered.
Create a column on your worksheet with a formula that concatenates the information in column B&L the formula would be =B1&L1 (copy this formula down the table). You can hide the column so nobody sees it. For this example, let's say you used column "M".
Select the entire Code or Month column (or both) and click the CONDITIONAL FORMATTING button on the Home tab, choose NEW RULE, USE FORMULA TO DETERMINE WHICH CELLS TO FORMAT, then enter the following formula: =COUNTIF($M$4:$M$1000,M1)>1 (note I am assuming your range of data is less than 1000 records, otherwise increase that number). Set the format to something like a red fill and instantly duplicates will be flagged. The user will also be able to quickly locate the record where this combination was already entered as that will turn red too.
If you really do want a macro to do this, you could simply write a loop to compares the active cell value of B(activerow) & L(activerow) to each previous B#&L# combination. If a match is found, use the intersect method to pop-up a the message. Here is really a good article about the intersect method: http://www.ozgrid.com/VBA/vba-intersect.htm.