Visual Basics Not working as intended.

Andrew Chaney 1 Reputation point
2022-05-26T19:35:34.31+00:00

all i want is for a drop down box to let me type in options and select from the suggested options (working Great) and based on the selection to hide or unhide columns (was working great until i added the dropdown box).... The dropdown box is linked to A4 if that helps.

here is my code can someone please tell me what i'm missing and doing wrong?

Private Sub ComboBox1_Change()
ComboBox1.ListFillRange = "DropDownList"
ComboBox1.DropDown

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRG As Range
Dim xHRow As Integer
Set xRG = Range("A4")
If Not Intersect(Target, xRG) Is Nothing Then
If Target.Value = "Accounting" Then
Application.Columns("D:AZ").Hidden = True
Application.Columns("C").Hidden = False
ElseIf Target.Value = "Executive" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("D").Hidden = False
ElseIf Target.Value = "Fund" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("E").Hidden = False
ElseIf Target.Value = "Area" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("F").Hidden = False
ElseIf Target.Value = "Facilities Management" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("g").Hidden = False
ElseIf Target.Value = "Grady's Way" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("H").Hidden = False
ElseIf Target.Value = "Community Assistance" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("I").Hidden = False
ElseIf Target.Value = "Rutger" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("J").Hidden = False
ElseIf Target.Value = "1616 Genesee St." Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("k").Hidden = False
ElseIf Target.Value = "Program Management" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("l").Hidden = False
ElseIf Target.Value = "Pathways" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("m").Hidden = False
ElseIf Target.Value = "Supported Housing" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("n").Hidden = False
ElseIf Target.Value = "SH Advocacy" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("o").Hidden = False
ElseIf Target.Value = "CYO" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("p").Hidden = False
ElseIf Target.Value = "Camp Nazareth" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("q").Hidden = False
ElseIf Target.Value = "Care Management" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("r").Hidden = False
ElseIf Target.Value = "Counseling" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("s").Hidden = False
ElseIf Target.Value = "Parenting" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("t").Hidden = False
ElseIf Target.Value = "Social Rec" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("u").Hidden = False
ElseIf Target.Value = "Transportation" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("v").Hidden = False
ElseIf Target.Value = "Albany St" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("w").Hidden = False
ElseIf Target.Value = "Churchill" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("x").Hidden = False
ElseIf Target.Value = "1626 Genesee" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("y").Hidden = False
ElseIf Target.Value = "N. George" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("z").Hidden = False
ElseIf Target.Value = "Oneida St" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("aa").Hidden = False
ElseIf Target.Value = "Noyes St" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("ab").Hidden = False
ElseIf Target.Value = "W. Thomas" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("ac").Hidden = False
ElseIf Target.Value = "Non-OMH" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("H:v").Hidden = False
ElseIf Target.Value = "OMH" Then
Application.Columns("C:AZ").Hidden = True
Application.Columns("w:AC").Hidden = False
End If
End If

End Sub

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.