JasonCExcel
New Member
- Joined
- Oct 31, 2023
- Messages
- 7
- Office Version
- 365
- Platform
- Windows
I have 2 sheets... on each sheet there is a macro that hides and unhides rows. Sheet 2 contains all the data to be hidden or unhidden.
When I code 2 runs to hide an entire section, and then code 1 runs to change the amount of rows (this is in unhidden sections) all of the hidden rows reappear and they are out of order. How can I run these two codes with the rows showing up again?
Code 1 - This code hides an entire section of rows entire section of rows:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Address = "$D$10" Then
If Target.Value = "3" Then
Sheets("Criteria Scoring").Rows("43:78").EntireRow.Hidden = True
Else
Sheets("Criteria Scoring").Rows("43:78").EntireRow.Hidden = False
End If
End If
End Sub
___________________________
This code repeats to to hide individual lines in each section (the correct
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Range("D7").Value = 1 Then
Rows("9:17").EntireRow.Hidden = True
Else
Rows("9:17").EntireRow.Hidden = False
If Range("D7").Value = 2 Then
Rows("10:17").EntireRow.Hidden = True
Else
Rows("10:17").EntireRow.Hidden = False
If Range("D7").Value = 3 Then
Rows("11:17").EntireRow.Hidden = True
Else
Rows("11:17").EntireRow.Hidden = False
If Range("D7").Value = 4 Then
Rows("12:17").EntireRow.Hidden = True
Else
Rows("12:17").EntireRow.Hidden = False
If Range("D7").Value = 5 Then
Rows("13:17").EntireRow.Hidden = True
Else
Rows("13:17").EntireRow.Hidden = False
If Range("D7").Value = 6 Then
Rows("14:17").EntireRow.Hidden = True
Else
Rows("14:17").EntireRow.Hidden = False
If Range("D7").Value = 7 Then
Rows("15:17").EntireRow.Hidden = True
Else
Rows("15:17").EntireRow.Hidden = False
If Range("D7").Value = 8 Then
Rows("16:17").EntireRow.Hidden = True
Else
Rows("16:17").EntireRow.Hidden = False
If Range("D7").Value = 9 Then
Rows("17:17").EntireRow.Hidden = True
Else
Rows("17:17").EntireRow.Hidden = False
End If
End If
End If
When I code 2 runs to hide an entire section, and then code 1 runs to change the amount of rows (this is in unhidden sections) all of the hidden rows reappear and they are out of order. How can I run these two codes with the rows showing up again?
Code 1 - This code hides an entire section of rows entire section of rows:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Address = "$D$10" Then
If Target.Value = "3" Then
Sheets("Criteria Scoring").Rows("43:78").EntireRow.Hidden = True
Else
Sheets("Criteria Scoring").Rows("43:78").EntireRow.Hidden = False
End If
End If
End Sub
___________________________
This code repeats to to hide individual lines in each section (the correct
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Range("D7").Value = 1 Then
Rows("9:17").EntireRow.Hidden = True
Else
Rows("9:17").EntireRow.Hidden = False
If Range("D7").Value = 2 Then
Rows("10:17").EntireRow.Hidden = True
Else
Rows("10:17").EntireRow.Hidden = False
If Range("D7").Value = 3 Then
Rows("11:17").EntireRow.Hidden = True
Else
Rows("11:17").EntireRow.Hidden = False
If Range("D7").Value = 4 Then
Rows("12:17").EntireRow.Hidden = True
Else
Rows("12:17").EntireRow.Hidden = False
If Range("D7").Value = 5 Then
Rows("13:17").EntireRow.Hidden = True
Else
Rows("13:17").EntireRow.Hidden = False
If Range("D7").Value = 6 Then
Rows("14:17").EntireRow.Hidden = True
Else
Rows("14:17").EntireRow.Hidden = False
If Range("D7").Value = 7 Then
Rows("15:17").EntireRow.Hidden = True
Else
Rows("15:17").EntireRow.Hidden = False
If Range("D7").Value = 8 Then
Rows("16:17").EntireRow.Hidden = True
Else
Rows("16:17").EntireRow.Hidden = False
If Range("D7").Value = 9 Then
Rows("17:17").EntireRow.Hidden = True
Else
Rows("17:17").EntireRow.Hidden = False
End If
End If
End If