Range Question ??

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

HYCH

My question is:

I have a range from H2:I32, within this range i have values of 1 and 0
spread throughout,

is it possible to run a vba macro to check for a 1 and then colour the
cell red,
i know how to use the 'Pattern.Solid Colorindex and numbers, but am
having very little luck with the actual code to check this range,
would prefer to have this running as a worksheet change event



Hych

Steve
 
I would suggest using conditional formats (formats->Conditional
formatting)

If it really needs to be vba though (and it doesn't sound like it
does... )

Public Sub colortest()
Dim wb As Workbook
Dim sht As Worksheet
Dim cell

Set wb = ThisWorkbook
Set sht = wb.Worksheets("Sheet1")

For Each cell In sht.Range("H2:I32")
If cell.Value = 1 Then
cell.Interior.ColorIndex = 1
Else
cell.Interior.ColorIndex = 0
End If
Next

End Sub

This actually changes between white and black... but you get the idea
 
I would suggest using conditional formats (formats->Conditional
formatting)

If it really needs to be vba though (and it doesn't sound like it
does... )

Public Sub colortest()
Dim wb As Workbook
Dim sht As Worksheet
Dim cell

Set wb = ThisWorkbook
Set sht = wb.Worksheets("Sheet1")

For Each cell In sht.Range("H2:I32")
If cell.Value = 1 Then
cell.Interior.ColorIndex = 1
Else
cell.Interior.ColorIndex = 0
End If
Next

End Sub

This actually changes between white and black... but you get the idea

thanks hal,

Would use Con From, but does have a tendency to make the filesize
larger than needed, where as i find Vba macro has less impact on file
sizes.


Thanks very much
Steve
 
Back
Top