I know very little about VBA but I created a simple If/ElseIf code that is apparently too large because when I make the necessary change on the spreadsheet that runs the code it gives me a "Compile error: Procedure too large" message. Essentially, the user has a drop down list in each cell O31 through O39 that they can choose either Yes or No. If every single drop down on O31 through O39 = "No" then rows 107:108 are not visible but if even one of those drop downs = "Yes" then rows 107:108 is visible. How can I loop the below code so that I can avoid the "Compile error: Procedure too large" message? The problem is that I have to do the below code on 10 different columns and each column has different options from the drop down list that could make their respective rows visible or not visible but the structure of each code is virtually identical. Then I also have other If/ElseIf codes added for other items which is why I'm exceeding the allowable limit. I'm using Office 365 if that matters.
Below is a sample of the code.
Below is a sample of the code.
VBA Code:
If Target.Column = 15 And Target.Row = 31 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O31").Select
ElseIf Target.Value = "No" And Range("O32").Value = "No" And Range("O33").Value = "No" And Range("O34").Value = "No" And Range("O35").Value = "No" And Range("O36").Value = "No" And Range("O37").Value = "No" And Range("O38").Value = "No" And Range("O39").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O31").Select
End If
End If
If Target.Column = 15 And Target.Row = 32 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O32").Select
ElseIf Target.Value = "No" And Range("O31").Value = "No" And Range("O33").Value = "No" And Range("O34").Value = "No" And Range("O35").Value = "No" And Range("O36").Value = "No" And Range("O37").Value = "No" And Range("O38").Value = "No" And Range("O39").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O32").Select
End If
End If
If Target.Column = 15 And Target.Row = 33 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O33").Select
ElseIf Target.Value = "No" And Range("O32").Value = "No" And Range("O31").Value = "No" And Range("O34").Value = "No" And Range("O35").Value = "No" And Range("O36").Value = "No" And Range("O37").Value = "No" And Range("O38").Value = "No" And Range("O39").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O33").Select
End If
End If
If Target.Column = 15 And Target.Row = 34 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O34").Select
ElseIf Target.Value = "No" And Range("O32").Value = "No" And Range("O33").Value = "No" And Range("O31").Value = "No" And Range("O35").Value = "No" And Range("O36").Value = "No" And Range("O37").Value = "No" And Range("O38").Value = "No" And Range("O39").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O34").Select
End If
End If
If Target.Column = 15 And Target.Row = 35 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O35").Select
ElseIf Target.Value = "No" And Range("O32").Value = "No" And Range("O33").Value = "No" And Range("O34").Value = "No" And Range("O31").Value = "No" And Range("O36").Value = "No" And Range("O37").Value = "No" And Range("O38").Value = "No" And Range("O39").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O35").Select
End If
End If
If Target.Column = 15 And Target.Row = 36 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O36").Select
ElseIf Target.Value = "No" And Range("O32").Value = "No" And Range("O33").Value = "No" And Range("O34").Value = "No" And Range("O35").Value = "No" And Range("O31").Value = "No" And Range("O37").Value = "No" And Range("O38").Value = "No" And Range("O39").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O36").Select
End If
End If
If Target.Column = 15 And Target.Row = 37 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O37").Select
ElseIf Target.Value = "No" And Range("O32").Value = "No" And Range("O33").Value = "No" And Range("O34").Value = "No" And Range("O35").Value = "No" And Range("O36").Value = "No" And Range("O31").Value = "No" And Range("O38").Value = "No" And Range("O39").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O37").Select
End If
End If
If Target.Column = 15 And Target.Row = 38 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O38").Select
ElseIf Target.Value = "No" And Range("O32").Value = "No" And Range("O33").Value = "No" And Range("O34").Value = "No" And Range("O35").Value = "No" And Range("O36").Value = "No" And Range("O37").Value = "No" And Range("O31").Value = "No" And Range("O39").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O38").Select
End If
End If
If Target.Column = 15 And Target.Row = 39 Then
If Target.Value <> "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = False
ActiveSheet.Range("O39").Select
ElseIf Target.Value = "No" And Range("O32").Value = "No" And Range("O33").Value = "No" And Range("O34").Value = "No" And Range("O35").Value = "No" And Range("O36").Value = "No" And Range("O37").Value = "No" And Range("O38").Value = "No" And Range("O31").Value = "No" Then
Application.Rows("107:108").Select
Application.Selection.EntireRow.Hidden = True
ActiveSheet.Range("O39").Select
End If
End If
Last edited by a moderator: