VBA Code Help

tinneytwin

New Member
Joined
May 9, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I need a VBA Code that will first look at the rows in Column F for matching data AND look in Column C for matching data (F & C will never match). For instance, if F2, F3, F4, F5, and F6 all match, then it needs to look in C2, C3, C4, C5, C6. For the rows in C that match (with the corresponding F matches), I need them to be highlighted. And keep repeating that pattern until all rows are highlighted.

I have a small portion of the data pictured here to show what I mean because it's hard to explain. In my picture, all column F are the same (only because this is a small portion of the data) but column C is different so I have them grouped/highlighted by F first then C. Column C is the name of a video and Column F is a date (with other information that I have truncated). The excel document will have thousands of rows it will need to go through and highlight. Right now I do this manually and it takes me forever because I have 26 different excel documents with thousands of rows in each document. I originally got VBA macro codes from someone who said they knew how to code macros, but none of their macro coding worked. I know nothing about coding.
(the colors don't have to be different. It could rotate back and forth between two colors)
 

Attachments

  • Capture.JPG
    Capture.JPG
    36.8 KB · Views: 12

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
If you don't mind using another column you could do this with conditional formatting and dispense with the VBA code. The first row of interest in column H is simply set to true, and then the subsequent rows in column H contain a formula
Excel Formula:
=IF(AND(F3=F2,C3=C2),H2,NOT(H2))

The conditional formatting is then just based on whether the value in H is TRUE or FALSE.

tinneytwin.xlsx
BCFGH
1
22.25.24 CHEM[2024-04-01]TRUE
32.25.24 CHEM[2024-04-01]TRUE
42.4.24 CHEM[2024-04-01]FALSE
53.13.24 CHEM[2024-04-01]TRUE
63.13.24 CHEM[2024-04-01]TRUE
73.13.24 CHEM[2024-04-01]TRUE
83.17.24 CHEM[2024-04-01]FALSE
93.17.24 CHEM[2024-04-01]FALSE
103.17.24 CHEM[2024-04-01]FALSE
113.20.24 CHEM[2024-04-01]TRUE
123.20.24 CHEM[2024-04-01]TRUE
133.20.24 CHEM[2024-04-01]TRUE
143.20.24 CHEM[2024-04-02]FALSE
153.20.24 CHEM[2024-04-03]TRUE
Sheet1
Cell Formulas
RangeFormula
H2H2=TRUE()
H3:H15H3=IF(AND(F3=F2,C3=C2),H2,NOT(H2))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:F15Expression=$H2=FALSEtextNO
C2:F15Expression=$H2textNO


Credit to the late Chip Pearson where I originally learned this idea.
 
Upvote 0
Solution
If you don't mind using another column you could do this with conditional formatting and dispense with the VBA code. The first row of interest in column H is simply set to true, and then the subsequent rows in column H contain a formula
Excel Formula:
=IF(AND(F3=F2,C3=C2),H2,NOT(H2))

The conditional formatting is then just based on whether the value in H is TRUE or FALSE.

tinneytwin.xlsx
BCFGH
1
22.25.24 CHEM[2024-04-01]TRUE
32.25.24 CHEM[2024-04-01]TRUE
42.4.24 CHEM[2024-04-01]FALSE
53.13.24 CHEM[2024-04-01]TRUE
63.13.24 CHEM[2024-04-01]TRUE
73.13.24 CHEM[2024-04-01]TRUE
83.17.24 CHEM[2024-04-01]FALSE
93.17.24 CHEM[2024-04-01]FALSE
103.17.24 CHEM[2024-04-01]FALSE
113.20.24 CHEM[2024-04-01]TRUE
123.20.24 CHEM[2024-04-01]TRUE
133.20.24 CHEM[2024-04-01]TRUE
143.20.24 CHEM[2024-04-02]FALSE
153.20.24 CHEM[2024-04-03]TRUE
Sheet1
Cell Formulas
RangeFormula
H2H2=TRUE()
H3:H15H3=IF(AND(F3=F2,C3=C2),H2,NOT(H2))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:F15Expression=$H2=FALSEtextNO
C2:F15Expression=$H2textNO


Credit to the late Chip Pearson where I originally learned this idea.
THANK YOU SO MUCH!!! You saved me so much time!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top