Forum Discussion
Jenstarzie
Apr 22, 2025Copper Contributor
VBA Coding to hide/unhide a row based on a cells colour
Hi, I'm fairly new to VBA and just getting to grips with some basic functions but am struggling with a slightly more complex one that i would like to implement. I have searched around but can't find...
Kidd_Ip
Apr 23, 2025MVP
How about this:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim cellColor As Long
Set ws = ThisWorkbook.Sheets("Sheet1") ' Change to your actual sheet name
' Check if the modified cell is A2
If Not Intersect(Target, ws.Range("A2")) Is Nothing Then
' Get the interior color of cell A2
cellColor = ws.Range("A2").Interior.Color
' Check if the color matches Red (adjust RGB value as needed)
If cellColor = RGB(255, 0, 0) Then
ws.Rows(2).Hidden = False ' Unhide row 2
Else
ws.Rows(2).Hidden = True ' Hide row 2
End If
End If
End Sub