compare values in a range of columns in excel VBA

new07

New Member
Joined
Jul 10, 2013
Messages
2
Hi,

After looking up this amazing forum website for answers, I decided to post a question because I do not understand excel vba all the way..

So I have values in Column L3 to AH3 and I would like to use if condition to see which values are less than 10.

I also have other rows where this comparison needs to be done but for now I can't even get simple if condition to work.

this is what I am doing

For Each cell In Range("L3:AH3")
If cell.Value < 10 Then
ActiveCell.Font.Color = vbRed
End If
Next cell

I am not getting any error but for some reason only first cell condition is compared and not the other cells..


please ask for more clarification, if this doesn't make sense..I really appreciate any input on this..
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You are real close, but this is messing you up:

ActiveCell.Font.Color = vbRed

The active cell is the cell currently selected (with the black border around it) on your worksheet. Regardless of what cells you loop through in your code, there is only one active cell.

You need to set the font on the current cell within your loop, like this:

cell.Font.Color = vbRed
 
Upvote 0
:cool:

you sir, are really awesome..thanks a bunch..
my 2 weeks of frustration gone in five minutes..

thank you again..


You are real close, but this is messing you up:

ActiveCell.Font.Color = vbRed

The active cell is the cell currently selected (with the black border around it) on your worksheet. Regardless of what cells you loop through in your code, there is only one active cell.

You need to set the font on the current cell within your loop, like this:

cell.Font.Color = vbRed
 
Upvote 0

Forum statistics

Threads
1,215,131
Messages
6,123,223
Members
449,091
Latest member
jeremy_bp001

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