vandango05
Board Regular
- Joined
- Oct 6, 2008
- Messages
- 110
I've written some code for a project and only part of it seems to run, here is the code:
Private Sub Worksheet_Calculate()
Dim MyResult As String
Application.ScreenUpdating = False
Application.EnableEvents = False
Rows("1:" & Sheet11.UsedRange.Rows.Count).EntireRow.Hidden = False
D1 = Sheet11.Cells(11, 2).Value
Select Case D1
Case "0", ""
Rows("24:32").EntireRow.Hidden = True
Case "2"
Rows("27:32").EntireRow.Hidden = True
Case "3"
Rows("28:32").EntireRow.Hidden = True
Case "4"
Rows("29:32").EntireRow.Hidden = True
Case "6"
Rows("31:32").EntireRow.Hidden = True
End Select
D2 = Sheet11.Cells(11, 3).Value
Select Case D2
Case "0", ""
Rows("33:41").EntireRow.Hidden = True
Case "2"
Rows("36:41").EntireRow.Hidden = True
Case "3"
Rows("37:41").EntireRow.Hidden = True
Case "4"
Rows("38:41").EntireRow.Hidden = True
Case "6"
Rows("40:41").EntireRow.Hidden = True
End Select
D3 = Sheet11.Cells(11, 4).Value
Select Case D3
Case "0", ""
Rows("42:50").EntireRow.Hidden = True
Case "2"
Rows("45:50").EntireRow.Hidden = True
Case "3"
Rows("46:50").EntireRow.Hidden = True
Case "4"
Rows("47:50").EntireRow.Hidden = True
Case "6"
Rows("49:50").EntireRow.Hidden = True
End Select
D4 = Sheet11.Cells(11, 5).Value
Select Case D4
Case "0", ""
Rows("51:59").EntireRow.Hidden = True
Case "2"
Rows("54:59").EntireRow.Hidden = True
Case "3"
Rows("55:59").EntireRow.Hidden = True
Case "4"
Rows("56:59").EntireRow.Hidden = True
Case "6"
Rows("58:59").EntireRow.Hidden = True
End Select
D5 = Sheet11.Cells(11, 6).Value
Select Case D5
Case "0", ""
Rows("60:68").EntireRow.Hidden = True
Case "2"
Rows("63:68").EntireRow.Hidden = True
Case "3"
Rows("64:68").EntireRow.Hidden = True
Case "4"
Rows("65:68").EntireRow.Hidden = True
Case "6"
Rows("67:68").EntireRow.Hidden = True
End Select
D6 = Sheet11.Cells(11, 7).Value
Select Case D6
Case "0", ""
Rows("60:68").EntireRow.Hidden = True
Case "2"
Rows("63:68").EntireRow.Hidden = True
Case "3"
Rows("64:68").EntireRow.Hidden = True
Case "4"
Rows("65:68").EntireRow.Hidden = True
Case "6"
Rows("67:68").EntireRow.Hidden = True
End Select
D7 = Sheet11.Cells(11, 8).Value
Select Case D7
Case "0", ""
Rows("78:86").EntireRow.Hidden = True
Case "2"
Rows("81:86").EntireRow.Hidden = True
Case "3"
Rows("82:86").EntireRow.Hidden = True
Case "4"
Rows("83:86").EntireRow.Hidden = True
Case "6"
Rows("85:86").EntireRow.Hidden = True
End Select
D8 = Sheet11.Cells(11, 9).Value
Select Case D8
Case "0", ""
Rows("87:95").EntireRow.Hidden = True
Case "2"
Rows("90:95").EntireRow.Hidden = True
Case "3"
Rows("91:95").EntireRow.Hidden = True
Case "4"
Rows("92:95").EntireRow.Hidden = True
Case "6"
Rows("94:95").EntireRow.Hidden = True
End Select
D9 = Sheet11.Cells(11, 10).Value
Select Case D9
Case "0", ""
Rows("96:104").EntireRow.Hidden = True
Case "2"
Rows("99:104").EntireRow.Hidden = True
Case "3"
Rows("101:104").EntireRow.Hidden = True
Case "4"
Rows("101:104").EntireRow.Hidden = True
Case "6"
Rows("103:104").EntireRow.Hidden = True
End Select
D10 = Sheet11.Cells(11, 11).Value
Select Case D10
Case "0", ""
Rows("105:113").EntireRow.Hidden = True
Case "2"
Rows("108:113").EntireRow.Hidden = True
Case "3"
Rows("109:113").EntireRow.Hidden = True
Case "4"
Rows("110:113").EntireRow.Hidden = True
Case "6"
Rows("112:113").EntireRow.Hidden = True
End Select
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Only cases D1, D2, D5, D7, D8 & D10 are running.
All target values are zero so all cases should be running. I have been staring at this for hours and rewritten a number of times, but can't seem to find any problems.
I've picked up VB through forums like this one which have been very helpful, code may not be the cleverest, but does the job I need it to. Hope someone can help?
Private Sub Worksheet_Calculate()
Dim MyResult As String
Application.ScreenUpdating = False
Application.EnableEvents = False
Rows("1:" & Sheet11.UsedRange.Rows.Count).EntireRow.Hidden = False
D1 = Sheet11.Cells(11, 2).Value
Select Case D1
Case "0", ""
Rows("24:32").EntireRow.Hidden = True
Case "2"
Rows("27:32").EntireRow.Hidden = True
Case "3"
Rows("28:32").EntireRow.Hidden = True
Case "4"
Rows("29:32").EntireRow.Hidden = True
Case "6"
Rows("31:32").EntireRow.Hidden = True
End Select
D2 = Sheet11.Cells(11, 3).Value
Select Case D2
Case "0", ""
Rows("33:41").EntireRow.Hidden = True
Case "2"
Rows("36:41").EntireRow.Hidden = True
Case "3"
Rows("37:41").EntireRow.Hidden = True
Case "4"
Rows("38:41").EntireRow.Hidden = True
Case "6"
Rows("40:41").EntireRow.Hidden = True
End Select
D3 = Sheet11.Cells(11, 4).Value
Select Case D3
Case "0", ""
Rows("42:50").EntireRow.Hidden = True
Case "2"
Rows("45:50").EntireRow.Hidden = True
Case "3"
Rows("46:50").EntireRow.Hidden = True
Case "4"
Rows("47:50").EntireRow.Hidden = True
Case "6"
Rows("49:50").EntireRow.Hidden = True
End Select
D4 = Sheet11.Cells(11, 5).Value
Select Case D4
Case "0", ""
Rows("51:59").EntireRow.Hidden = True
Case "2"
Rows("54:59").EntireRow.Hidden = True
Case "3"
Rows("55:59").EntireRow.Hidden = True
Case "4"
Rows("56:59").EntireRow.Hidden = True
Case "6"
Rows("58:59").EntireRow.Hidden = True
End Select
D5 = Sheet11.Cells(11, 6).Value
Select Case D5
Case "0", ""
Rows("60:68").EntireRow.Hidden = True
Case "2"
Rows("63:68").EntireRow.Hidden = True
Case "3"
Rows("64:68").EntireRow.Hidden = True
Case "4"
Rows("65:68").EntireRow.Hidden = True
Case "6"
Rows("67:68").EntireRow.Hidden = True
End Select
D6 = Sheet11.Cells(11, 7).Value
Select Case D6
Case "0", ""
Rows("60:68").EntireRow.Hidden = True
Case "2"
Rows("63:68").EntireRow.Hidden = True
Case "3"
Rows("64:68").EntireRow.Hidden = True
Case "4"
Rows("65:68").EntireRow.Hidden = True
Case "6"
Rows("67:68").EntireRow.Hidden = True
End Select
D7 = Sheet11.Cells(11, 8).Value
Select Case D7
Case "0", ""
Rows("78:86").EntireRow.Hidden = True
Case "2"
Rows("81:86").EntireRow.Hidden = True
Case "3"
Rows("82:86").EntireRow.Hidden = True
Case "4"
Rows("83:86").EntireRow.Hidden = True
Case "6"
Rows("85:86").EntireRow.Hidden = True
End Select
D8 = Sheet11.Cells(11, 9).Value
Select Case D8
Case "0", ""
Rows("87:95").EntireRow.Hidden = True
Case "2"
Rows("90:95").EntireRow.Hidden = True
Case "3"
Rows("91:95").EntireRow.Hidden = True
Case "4"
Rows("92:95").EntireRow.Hidden = True
Case "6"
Rows("94:95").EntireRow.Hidden = True
End Select
D9 = Sheet11.Cells(11, 10).Value
Select Case D9
Case "0", ""
Rows("96:104").EntireRow.Hidden = True
Case "2"
Rows("99:104").EntireRow.Hidden = True
Case "3"
Rows("101:104").EntireRow.Hidden = True
Case "4"
Rows("101:104").EntireRow.Hidden = True
Case "6"
Rows("103:104").EntireRow.Hidden = True
End Select
D10 = Sheet11.Cells(11, 11).Value
Select Case D10
Case "0", ""
Rows("105:113").EntireRow.Hidden = True
Case "2"
Rows("108:113").EntireRow.Hidden = True
Case "3"
Rows("109:113").EntireRow.Hidden = True
Case "4"
Rows("110:113").EntireRow.Hidden = True
Case "6"
Rows("112:113").EntireRow.Hidden = True
End Select
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Only cases D1, D2, D5, D7, D8 & D10 are running.
All target values are zero so all cases should be running. I have been staring at this for hours and rewritten a number of times, but can't seem to find any problems.
I've picked up VB through forums like this one which have been very helpful, code may not be the cleverest, but does the job I need it to. Hope someone can help?