Interior Color Multiple Columns

gripper

Board Regular
Joined
Oct 29, 2002
Messages
176
Good Afternoon,

I am working on a project as follows.

I have a excel sheet that has multiple columns with data. Focusing only on Columns("L:V" & lrow)

I want to loop through each cell in these columns with the following criteria

If Cell > 0 then highlight as green
If Cell < 0 then highlight as Red and make the text Bold and the font size equal to 14 (current default size is 11)

Each column is the same length always but that length does vary upon the data imported.

I appreciate the direction and assistance with this matter.

I want to solve this with VBA which will be used in part in other parts of this project and do not want to use the built in conditional formatting

Thank you.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hello Gripper,
can this code be helpful?
Test on small data size and increase size with few steps to see does work properly.
Don't forget to set sheet name.
VBA Code:
Sub ColorCellFormatFonts()

    Dim varWS As Worksheet
    Dim varNRows As Long
    Dim varRange1 As Range, varRange2 As Range
    
    Application.ScreenUpdating = False
'set your worksheet name
    Set varWS = Worksheets("YourSheetName")
    varNRows = varWS.Range("L" & Rows.Count).End(xlUp).Row
    Set varRange2 = varWS.Range("L1:V" & varNRows)
    For Each varRange1 In varRange2
        If varRange1.Value > 0 Then
            varRange1.Interior.Color = RGB(0, 255, 0)
        End If
        If varRange1.Value < 0 Then
            With varRange1
                .Interior.Color = RGB(255, 0, 0)
                .Font.Bold = True
                .Font.Size = 14
            End With
        End If
    Next varRange1
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Excel Max

Thank you for the help. This did the trick.

I appreciate it

Happy New Years!
 
Upvote 0
Thank you and Happy New Year to you.
I'm happy too if we did the trick. ?
 
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,944
Members
449,095
Latest member
nmaske

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