Forum Discussion
VBA statement with a IF
- May 30, 2022
Sub color() Dim i As Integer Range("D:D").Interior.ColorIndex = 0 For i = 2 To 27 If Cells(i, 4).Value < Date - 60 And Cells(i, 5) <> "specific group" Then Cells(i, 4).Interior.ColorIndex = 3 Else If Cells(i, 4).Value < Date - 30 And Cells(i, 5) <> "specific group" Then Cells(i, 4).Interior.ColorIndex = 6 Else End If End If Next i End SubMaybe with these lines of code. In the attached file you can click the button in cell H2 to start the macro.
You don't need VBA for that, it can be done with conditional formatting. See the attached demo workbook.
Select Conditional Formatting > Manage Rules... on the Home tab of the ribbon to inspect the rules.
THank you for you answer.
But i have a drop down list row in the column "assigment group" and when i change the group there, the color doesn´t change like your demo spreadsheet.
- HansVogelaarMay 31, 2022MVP
Here is a version with a data validation drop-down in the Assignment Group column.
- Luiz_Martins_86May 31, 2022Copper ContributorWhat you did different from the other ? You only created the drop down list ?
In my spreadsheet doesn´t work yet 😞- HansVogelaarMay 31, 2022MVP
I only added data validation to column B.
Could you attach a sample workbook (without sensitive data), or if that is not possible, make it available through OneDrive, Google Drive, Dropbox or similar? Thanks in advance.