Screamer_87
New Member
- Joined
- Oct 17, 2019
- Messages
- 2
Hello colleauges,
I came across a problem to be honest last time I used VBA was 3 years ago, so today I'm preparing a live sheet which shift cells dependant on cell value (product number). I tried to tweak around the code but it seems it just getting commands just from last lines of code for value 9. I don't remember do I need to loop it or something if anyone can shed a light for me I would be thankful.
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Range("D7") = "1" Then
Rows("55:69").EntireRow.Hidden = True
Else
Rows("55:69").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "1" Then
Rows("85:112").EntireRow.Hidden = True
Else
Rows("85:112").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "1" Then
Rows("115:123").EntireRow.Hidden = True
Else
Rows("115:123").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "1" Then
Rows("133:141").EntireRow.Hidden = True
Else
Rows("133:141").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "2" Then
Rows("40:54").EntireRow.Hidden = True
Else
Rows("40:54").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "2" Then
Rows("85:112").EntireRow.Hidden = True
Else
Rows("85:112").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "2" Then
Rows("124:141").EntireRow.Hidden = True
Else
Rows("124:141").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "4" Then
Rows("55:69").EntireRow.Hidden = True
Else
Rows("55:69").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "4" Then
Rows("113:141").EntireRow.Hidden = True
Else
Rows("113:141").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "9" Then
Rows("55:69").EntireRow.Hidden = True
Else
Rows("55:69").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "9" Then
Rows("85:112").EntireRow.Hidden = True
Else
Rows("85:112").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "9" Then
Rows("115:132").EntireRow.Hidden = True
Else
Rows("115:132").EntireRow.Hidden = False
End If
End Sub
I came across a problem to be honest last time I used VBA was 3 years ago, so today I'm preparing a live sheet which shift cells dependant on cell value (product number). I tried to tweak around the code but it seems it just getting commands just from last lines of code for value 9. I don't remember do I need to loop it or something if anyone can shed a light for me I would be thankful.
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Range("D7") = "1" Then
Rows("55:69").EntireRow.Hidden = True
Else
Rows("55:69").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "1" Then
Rows("85:112").EntireRow.Hidden = True
Else
Rows("85:112").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "1" Then
Rows("115:123").EntireRow.Hidden = True
Else
Rows("115:123").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "1" Then
Rows("133:141").EntireRow.Hidden = True
Else
Rows("133:141").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "2" Then
Rows("40:54").EntireRow.Hidden = True
Else
Rows("40:54").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "2" Then
Rows("85:112").EntireRow.Hidden = True
Else
Rows("85:112").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "2" Then
Rows("124:141").EntireRow.Hidden = True
Else
Rows("124:141").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "4" Then
Rows("55:69").EntireRow.Hidden = True
Else
Rows("55:69").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "4" Then
Rows("113:141").EntireRow.Hidden = True
Else
Rows("113:141").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "9" Then
Rows("55:69").EntireRow.Hidden = True
Else
Rows("55:69").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "9" Then
Rows("85:112").EntireRow.Hidden = True
Else
Rows("85:112").EntireRow.Hidden = False
End If
If ActiveSheet.Range("D7") = "9" Then
Rows("115:132").EntireRow.Hidden = True
Else
Rows("115:132").EntireRow.Hidden = False
End If
End Sub