One way:
Option Explicit
Sub SelectiveFormatPopUp()
' highlight anything < 0 red, > 2 Red, [ 0,1,2 Black ]
Dim c As Range
Dim myCell As Range
Dim myVal As Variant 'numbers or text
myVal = Worksheets("Master").Range("n8").Value
On Error GoTo Finish
'If it's just column N
Set c = Range("n11:N" & myVal)
'or
'Set c = Range("n11:X" & myVal)
'if you want N11:X (whatever is in range("N8"))
For Each myCell In c
If Val(myCell.Value) > 2 _
Or Val(myCell.Value) < 0 Then
myCell.Font.Bold = True
myCell.Font.Color = vbRed
Else
myCell.Font.Bold = True
myCell.Font.Color = vbBlack
End If
Next myCell
Finish:
End Sub
This line:
Set c = Range("n11:N" & myVal)
points at the activesheet. I like to be more explicit and make sure I specify
the sheet.
Set c = activesheet.Range("n11:N" & myVal)
I could also point at a different sheet:
Set c = worksheets("sheet99").Range("n11:N" & myVal)
===
I also changed Item to myCell. VBA has its own Item keyword. And I like to
stay away from those when I use my own variables.
can you help me with the last part ?
here is my script,
start here --------
Sub SelectiveFormatPopUp()
' highlight anything < 0 red, > 2 Red, [ 0,1,2 Black ]
Dim c As Range
Dim myVal As Variant 'numbers or text
myVal = Worksheets("Master").Range("n8").Value
On Error GoTo Finish
Set c = Range("n11:myVal") <------- not right, can you help me out
with this ?
For Each Item In c
If Val(Item) > 2 Or Val(Item) < 0 Then
Item.Font.Bold = True
Item.Font.COLOR = vbRed
Else
Item.Font.Bold = True
Item.Font.COLOR = vbBlack
End If
Next Item
Finish:
End Sub