Long story short, I have specific columns on the right side of my worksheet that will 'show' or 'hide' depending on input from the left side of the worksheet. If it was just me, I would do this manually and not bat an eye, but I give this worksheet to a bunch of people who think the only way to enter a formula is by clicking the Sigma button.
The Target.Address of the first 3 If/Else statements refer to cells that are drop down lists and the statements cause the columns to hide/show as intended. My problem lies with the last 3 If/Else Statements of the Sub. Basically, I want columns S, Y, and AE to be visible only when 2 different drop down lists are in a specific combination. I couldn't figure out how to do that using VBA alone so I created "helper cells" using a formula in S3, Y3, and AE3; the formula in S3 looks like this: =IF(OR(AND($M$3="Yes",$L$5=""),$M$3="No",$M$3=""),"X","")
The formulas in Y3 and AE3 are similar, just $L$5 being replaced with $M$5 and $N$5 respectively. I think the problem is that I'm telling it to look for a value of "X" and it sees the formula. I think Indirect needs to be used in some way so that it looks at the result of the formula instead of the formula itself, but I have yet to find how to do that. Any ideas on how to fix my issue?
*Side Note* I feel like my code could probably be simplified, but I only know enough VBA to be dangerous; what I have was pieced together off many, many searches on the subject. If someone can simplify it, by all means, please and thank you.
The Target.Address of the first 3 If/Else statements refer to cells that are drop down lists and the statements cause the columns to hide/show as intended. My problem lies with the last 3 If/Else Statements of the Sub. Basically, I want columns S, Y, and AE to be visible only when 2 different drop down lists are in a specific combination. I couldn't figure out how to do that using VBA alone so I created "helper cells" using a formula in S3, Y3, and AE3; the formula in S3 looks like this: =IF(OR(AND($M$3="Yes",$L$5=""),$M$3="No",$M$3=""),"X","")
The formulas in Y3 and AE3 are similar, just $L$5 being replaced with $M$5 and $N$5 respectively. I think the problem is that I'm telling it to look for a value of "X" and it sees the formula. I think Indirect needs to be used in some way so that it looks at the result of the formula instead of the formula itself, but I have yet to find how to do that. Any ideas on how to fix my issue?
*Side Note* I feel like my code could probably be simplified, but I only know enough VBA to be dangerous; what I have was pieced together off many, many searches on the subject. If someone can simplify it, by all means, please and thank you.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$L$5" Then
If Target.Value = "" Then
Application.Range("P:R,T:U").Select
Application.Selection.EntireColumn.Hidden = True
Else
Application.Range("P:R,T:U").Select
Application.Selection.EntireColumn.Hidden = False
End If
End If
If Target.Address = "$M$5" Then
If Target.Value = "" Then
Application.Range("V:X,Z:AA").Select
Application.Selection.EntireColumn.Hidden = True
Else
Application.Range("V:X,Z:AA").Select
Application.Selection.EntireColumn.Hidden = False
End If
End If
If Target.Address = "$N$5" Then
If Target.Value = "" Then
Application.Range("AB:AD,AF:AG").Select
Application.Selection.EntireColumn.Hidden = True
Else
Application.Range("AB:AD,AF:AG").Select
Application.Selection.EntireColumn.Hidden = False
End If
End If
If Target.Address = "$S$3" Then
If Target.Value = "X" Then
Application.Range("S:S").Select
Application.Selection.EntireColumn.Hidden = True
Else
Application.Range("S:S").Select
Application.Selection.EntireColumn.Hidden = False
End If
End If
If Target.Address = "$Y$3" Then
If Target.Value = "X" Then
Application.Range("Y:Y").Select
Application.Selection.EntireColumn.Hidden = True
Else
Application.Range("Y:Y").Select
Application.Selection.EntireColumn.Hidden = False
End If
End If
If Target.Address = "$AE$3" Then
If Target.Value = "X" Then
Application.Range("AE:AE").Select
Application.Selection.EntireColumn.Hidden = True
Else
Application.Range("AE:AE").Select
Application.Selection.EntireColumn.Hidden = False
End If
End If
End Sub