Color Fill on Cells

niko4

New Member
Joined
May 3, 2012
Messages
19
I am trying to figure out how to change the fill color on each row of data that contains has a matching value from another spreadsheet. My code works but it is filling the entire row across all of the columns on the spreadsheet, I would like to only fill the columns that have data in them...in this case A:D. I'm using a For Each loop and I'm not sure how to specifiy the column range. Thanks!

Here is my current code.

Dim lRow1, lRow2, X As Integer


lRow2 = Sheets("By Resource - All Data").Range("B" & Rows.Count).End(xlUp).Row
Sheets("Priorities").Activate
lRow1 = Range("B" & Rows.Count).End(xlUp).Row
X = 1

For Each cell In Range("B3:B" & lRow1)
Do
X = X + 1
If cell.Value = Sheets("By Resource - All Data").Cells(X, "B") Then
Rows(cell.Row).Interior.ColorIndex = 2
End If
Loop Until X = lRow2
X = 1
Next cell
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Why are you using code for this?
This should be pretty easy to do with Conditional Formatting.
 
Upvote 0
Hi,

Wouldn't Just

Code:
Range("A" & cell.Row & ":D" & cell.Row).Interior.ColorIndex = 2

Do the trick ?

And as Joe4 said you probably can use Conditional formatting.
 
Last edited:
Upvote 0
That was the first thing I tried but I must not of done it correctly. It does work! Thank you!!!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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