Hey everyone I have some code that I want to have auto execute when a cell changes its value.
I have 2 worksheets (Worksheet and Summary). You enter information into the Worksheet Sheet and it calculates values in the Summary Sheet. I want my code to execute if the value of a cell changes on the Summary sheet. Note: the summary sheet's cells are never actively changed meaning no one will be allowed to click in a cell on the summary sheet and change something.
I set it to Worksheet_Change(...) but it doesnt work, If I set it to self named function like HideRows() and then just run it manually, it works fine.
So how can i get the code to auto execute if a cell on summary changes?
here is the code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim cell As Range
Set rng = Sheets("Summary").Range("G10:P10")
Sheets("Summary").Range("11:19, 23:31, 43:51, 54:62, 78:86, 90:98").EntireRow.Hidden = True
For Each cell In rng
If cell >= 2000 And cell < 4000 Then
Sheets("Summary").Range("11:11, 23:23, 43:43, 54:54, 78:78, 90:90").EntireRow.Hidden = False
Sheets("Summary").Range("12:19, 24:31, 44:51, 55:62, 79:86, 91:98").EntireRow.Hidden = True
End If
If cell.Value >= 4000 And cell.Value < 6000 Then
Sheets("Summary").Range("11:12, 23:24, 43:44, 54:55, 78:79, 90:91").EntireRow.Hidden = False
Sheets("Summary").Range("13:19, 25:31, 45:51, 56:62, 80:86, 92:98").EntireRow.Hidden = True
End If
If cell.Value >= 6000 And cell.Value < 8000 Then
Sheets("Summary").Range("11:13, 23:25, 43:45, 54:56, 78:80, 90:92").EntireRow.Hidden = False
Sheets("Summary").Range("14:19, 26:31, 46:51, 57:62, 81:86, 93:98").EntireRow.Hidden = True
End If
If cell.Value >= 8000 And cell.Value < 10000 Then
Sheets("Summary").Range("11:14, 23:26, 43:46, 54:57, 78:81, 90:93").EntireRow.Hidden = False
Sheets("Summary").Range("15:19, 27:31, 47:51, 58:62, 82:86, 94:98").EntireRow.Hidden = True
End If
If cell.Value >= 10000 And cell.Value < 12000 Then
Sheets("Summary").Range("11:15, 23:27, 43:47, 54:58, 78:82, 90:94").EntireRow.Hidden = False
Sheets("Summary").Range("16:19, 28:31, 48:51, 59:62, 83:86, 95:98").EntireRow.Hidden = True
End If
If cell.Value >= 12000 And cell.Value < 14000 Then
Sheets("Summary").Range("11:16, 23:28, 43:48, 54:59, 78:83, 90:95").EntireRow.Hidden = False
Sheets("Summary").Range("17:19, 29:31, 49:51, 60:62, 84:86, 96:98").EntireRow.Hidden = True
End If
If cell.Value >= 14000 And cell.Value < 16000 Then
Sheets("Summary").Range("11:17, 23:29, 43:49, 54:60, 78:84, 90:96").EntireRow.Hidden = False
Sheets("Summary").Range("18:19, 30:31, 50:51, 61:62, 85:86, 97:98").EntireRow.Hidden = True
End If
If cell.Value >= 16000 And cell.Value < 18000 Then
Sheets("Summary").Range("11:18, 23:30, 43:50, 54:61, 78:85, 90:97").EntireRow.Hidden = False
Sheets("Summary").Range("19:19, 31:31, 51:51, 62:62, 86:86, 98:98").EntireRow.Hidden = True
End If
If cell.Value >= 18000 And cell.Value < 20000 Then
Sheets("Summary").Range("11:19, 23:31, 43:51, 54:62, 78:86, 90:98").EntireRow.Hidden = False
End If
Next
End Sub