Hello,
I am trying to figure out how to test some cells in excel using VBA code to change a color of a cell based on the results of a test. I have it figured out for one cell but have been unable to figure out how to test multiple cells using the same format. Using Excel 2007 software. Tried using range and keep getting a type mismatch 13 error. Used both Range("A1:B7") and [A1:B7] with no luck. Below is my code that works with one cell being tested:
Sub Cell_Color()
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("Sheet1")
If Cells(2, 2).value = "x" Then Cells(1, 1).Interior.ColorIndex = 3
If Cells(2, 2).value = "d" Then Cells(1, 1).Interior.ColorIndex = 6
If Cells(2, 2).value = " " Then Cells(1, 1).Interior.ColorIndex = 4
End Sub
The goal is to test multiple cells for same values and have each one independently respond with the appropriate color code.
I am trying to figure out how to test some cells in excel using VBA code to change a color of a cell based on the results of a test. I have it figured out for one cell but have been unable to figure out how to test multiple cells using the same format. Using Excel 2007 software. Tried using range and keep getting a type mismatch 13 error. Used both Range("A1:B7") and [A1:B7] with no luck. Below is my code that works with one cell being tested:
Sub Cell_Color()
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("Sheet1")
If Cells(2, 2).value = "x" Then Cells(1, 1).Interior.ColorIndex = 3
If Cells(2, 2).value = "d" Then Cells(1, 1).Interior.ColorIndex = 6
If Cells(2, 2).value = " " Then Cells(1, 1).Interior.ColorIndex = 4
End Sub
The goal is to test multiple cells for same values and have each one independently respond with the appropriate color code.