I have a spreadsheet with multiple tables within one sheet.
I have crated a VBA code that allows a) multiple selections within acell from a drop down list and b) show/hides rows depending on the option selected in a different cell.
The VBA code functions correctly, however the issue I am running into is when a row is added above the row range for the show/hide code. Although I have defined the range in the Name Manager, it does not shift the row number auotomatically. I need the code to change dynamically when a row is added or deleted.
Here is the VBA code I am using:
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$B$33" Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
If Not Application.Intersect(Range("B35"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value
Case Is = "No": Range("36:37,TRACK").EntireRow.Hidden = True
Range("91:91").EntireRow.Hidden = False
Case Is = "Yes": Range("91:91").EntireRow.Hidden = True
Range("36:37,TRACK").EntireRow.Hidden = False
End Select
End If
End Sub
Here is the Defined Name Range:
Thanks for the help!
I have crated a VBA code that allows a) multiple selections within acell from a drop down list and b) show/hides rows depending on the option selected in a different cell.
The VBA code functions correctly, however the issue I am running into is when a row is added above the row range for the show/hide code. Although I have defined the range in the Name Manager, it does not shift the row number auotomatically. I need the code to change dynamically when a row is added or deleted.
Here is the VBA code I am using:
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$B$33" Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
If Not Application.Intersect(Range("B35"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value
Case Is = "No": Range("36:37,TRACK").EntireRow.Hidden = True
Range("91:91").EntireRow.Hidden = False
Case Is = "Yes": Range("91:91").EntireRow.Hidden = True
Range("36:37,TRACK").EntireRow.Hidden = False
End Select
End If
End Sub
Here is the Defined Name Range:
Thanks for the help!