Reputation: 61
I have a spreadsheet that has a number of cells styled "Good" and "Bad" From the home tab. I would like my VBA program to check if a cell is formatted as "Good" or "Bad". I can't find any answers on here about the style of a cell. I can tell you what I have tried and found it not working:
if Range("f2").style = "good" then do stuff end if
Excel 2010 Thanks for any help
Upvotes: 2
Views: 6497
Reputation: 4568
When I used the "Record Macro" to record me changing these this is the code generated :
Range("I6").Select
Selection.Style = "Bad"
Range("I9").Select
Selection.Style = "Good"
I conclude that you need to use an upper case "G" ie "Good" not "good"
Upvotes: 2
Reputation: 55682
To cover options something like
Sub TellMe()
Select Case [f2].Style
Case "Good"
Debug.Print "style = Good"
Case "Bad"
Debug.Print "style = Bad"
Case Else
Debug.Print [f2].Style
End Select
End Sub
Upvotes: 0