Color cells vba for next in each worksheet

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
Hi guys,
I have a table range ("C3:BO12") in 25 worksheets in one book. I would like to do is color interior green if value is =>0 and red if <0 in each worksheet.

Would this work. Not at computer cos it's broken but been playing on my mind.

Sub condition
Dim ws As worksheet
Dim cell as range
For each ws in Activeworkbook.worksheet
For each cell in range("C3:BO12")
If cell.value =>0 Then
Cell.interior.color = vbGreen
ElseIf cell.value < 0 Then
Cell.interior.color = vbRed
EndIf
Next cell
Next ws
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I see two syntax changes
Code:
For each ws in Activeworkbook.worksheet[COLOR="Red"]s[/COLOR]
    For each cell in [COLOR="red"]ws.[/COLOR]range("C3:BO12")
Or have you considered using conditional formatting.
 
Upvote 0
This only part of problem I have I have a growing table that uses a macro that opens another workbook to get data from I want something that will condition cell depending value. Changes week on week.
Also the table has ref to other cells in table Eg for quarter of the year. But thanks for ur help.
 
Upvote 0
Perhaps this will do what you want.
Code:
Sub Macro1()
    With ThisWorkbook
        With .Worksheets(1).Range("C3:BO12")
            With .Interior
                .ColorIndex = 10
                .Pattern = xlSolid
            End With
            .FormatConditions.Delete
            .FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="0"
            .FormatConditions(1).Interior.ColorIndex = 3
        End With
        
        .Worksheets.FillAcrossSheets Range:=.Worksheets(1).Range("C3:BO12"), Type:=xlFillWithFormats
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

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