Devastathor
New Member
- Joined
- May 13, 2019
- Messages
- 1
So I'm really new to VBA and have been looking everywhere for a solution to my problem. Here's what I've come up with this far.
I'm sure there's a much easier way to do it, but since every section is for a different sheet and each sheet will be different on a day to day basis I don't see how.
Basically Z2,3,4 is the production orders for monday on a production line. Z5,6,7 is for tuesday and so on monday to friday.
Z17,18,19 is production orders for monday on another production line, Z20,21,22 tuesday and so on monday to friday.
So I have to repeat this macro for each day of the week, on each production line.
Thing is, the amount of orders for each day can vary from 1 to 3, so I want to hide some parts of the sheets depending on wether or not there is 1, 2 or 3 production orders on that particular day.
I've also chosen to hide the sheet alltogether if there's no production orders on that day. This code is placed in the sheet where the production data for the following week is imported.
Am I on to something here or do I have to do it another way?
Any thoughts or help appreciated.
I'm sure there's a much easier way to do it, but since every section is for a different sheet and each sheet will be different on a day to day basis I don't see how.
Basically Z2,3,4 is the production orders for monday on a production line. Z5,6,7 is for tuesday and so on monday to friday.
Z17,18,19 is production orders for monday on another production line, Z20,21,22 tuesday and so on monday to friday.
So I have to repeat this macro for each day of the week, on each production line.
Thing is, the amount of orders for each day can vary from 1 to 3, so I want to hide some parts of the sheets depending on wether or not there is 1, 2 or 3 production orders on that particular day.
I've also chosen to hide the sheet alltogether if there's no production orders on that day. This code is placed in the sheet where the production data for the following week is imported.
Am I on to something here or do I have to do it another way?
Any thoughts or help appreciated.
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("Skjema Man L2").Rows("1:321").EntireRow.Hidden = False
If [Z2] = 0 Then
Sheets("Skjema Man L2").Visible = False
Else
Sheets("Skjema Man L2").Visible = True
End If
If [Z3] = 0 Then
Sheets("Skjema Man L2").Rows("112:321").EntireRow.Hidden = True
ElseIf [Z4] = 0 Then
Sheets("Skjema Man L2").Rows("217:321").EntireRow.Hidden = True
End If
Sheets("Skjema Man L3").Rows("1:321").EntireRow.Hidden = False
If [Z17] = 0 Then
Sheets("Skjema Man L3").Visible = False
Else
Sheets("Skjema Man L3").Visible = True
End If
If [Z18] = 0 Then
Sheets("Skjema Man L3").Rows("112:321").EntireRow.Hidden = True
ElseIf [Z19] = 0 Then
Sheets("Skjema Man L3").Rows("217:321").EntireRow.Hidden = True
End If
End Sub