I need to create a macro that goes in to a worksheet and looks at the contents of a range to see if it contains any number other than zero. If it does, I need it to turn a separate cell yellow.
'assign variables
Dim rngSat As Range
Dim rngSun As Range
Dim wsOT As Worksheet
Set wsOT = _
Application.Workbooks("Weekend OT.xls").Worksheets("7-8")
Set rngSat = _
Application.Workbooks("Weekend OT.xls").Worksheets("7-8").Range("G37:G40")
Set rngSun = _
Application.Workbooks("Weekend OT.xls").Worksheets("7-8").Range("J37:J40")
If rngSat.Value <> 0 Then
wsOT.Cells("Y5:Y6").Interior.Color = vbYellow
End If
If rngSun.Value <> 0 Then
wsOT.Cells("Y13:Y14").Interior.Color = vbYellow
End If
Here is what I ended up using
'See if anyone is working Saturday 2nd Shift, if they are shade support cells yellow
If Application.WorksheetFunction.Sum(rngSat) <> 0 Then
wsOT.Range("Y5:Y6,Y20,Y26,Y32,AA17,AA21:AA22,AA25,Y45:AA45").Interior.Color = vbYellow
Else
wsOT.Range("Y5:Y6,Y20,Y26,Y32,AA17,AA21:AA22,AA25,Y45:AA45").Interior.Color = vbWhite
End If
'See if anyone is working Sunday 2nd Shift, if they are shade support cells yellow
If Application.WorksheetFunction.Sum(rngSun) <> 0 Then
wsOT.Range("Y13:Y14,Y22,Y28,Y34,Y48:AA48").Interior.Color = vbYellow
Else
wsOT.Range("Y13:Y14,Y22,Y28,Y34,Y48:AA48").Interior.Color = vbWhite
End If
'Change background color to white if info has been provided
For Each Cell In rngComp
If Cell.Text = "" Then
Cell.Interior.Color = vbYellow
ElseIf Cell.Text = "TBD" Then
Cell.Interior.Color = vbYellow
Else
Cell.Interior.Color = vbWhite
End If
Next Cell
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 1  Reply