Macro to format cells based on whether or not their contents are in a list on another tab

tcorbs

New Member
Joined
May 17, 2011
Messages
9
So I have a range of cells, specifically A1:LH1100 on Sheet 2. Some of these cells are blank, some contain an ID number.
On Sheet 1, I have a dataset which contains ID Numbers in column A, and other descriptive fields in columns B-E

I am lookking for a macro that will go through each cell in that range on Sheet 2 (A1:LH1100) and perform the following:

-if the cell is empty, go to next cell
-if the cell contains an ID number
-if the ID number is on the list on Sheet 1, format the cell to be filled "red"
-if the ID number is not on the list on Sheet 1, format the cell to be filled "blue"

Ideally I would like to easily be able to expand this and format based on whether that cell ID is not only listed on Sheet 1, but also meets other criteria (in columns B-E)

I was thinking I could do some sort of "if ( sumifs" formula in VBA but I'm not sure. The code that I was trying was a For Each loop and it looked like it would work for about the first 100 rows and then stop, though none of those cells would be formatted any differently. So I am thinking I may have been way off.

Please help. Thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Are there any formulas on Sheet2 in the range A1:LH1100?
 
Upvote 0
This is my code so far...which is not working

Sub All_Sold()


Dim all_cells As Range
Dim cell As Range

Set all_cells = Sheets("Sheet 2").Range("A1:LH1100")

For Each cell In all_cells


If cell.Text <> "" Then
If Application.WorksheetFunction.CountIfs(Sheets("Sheet 1").Range("A1:A25000"), cell.Text) > 0 Then cell.Interior.ColorIndex = 3 Else
cell.Interior.ColorIndex = 6
End If

Next


End Sub
 
Upvote 0
Nevermind...I'm an idiot. Code was working but I had conditionally formatted the cells such that I wasn't seeing any results. I apologize to anyone whose time I wasted with this.

I guess the lesson to be learned here is that if there is no error message, it is often because there is no error. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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