jeudi 16 novembre 2017

If then Else multiple Elseif needed how to would it work?

Sorry extremely new to VBA and so far it's been fun, but not sure where to go from here.

I have this code and it works based on a cell value

Want to hide if they pick drop down and value shows other hide those columns

So I have 3 groups of columns

Team roughly 20 columns other roughly 20 columns and match roughly 20 columns in that order left to right.

so I figured out how to hide the team, but how do I make it to hide team and other if the user chooses Match?

Guess it's a multiple condition if situation. Thoughts?

Sub HideColumns()

' hides "user" team columns

If Range("O2").Text = "OTHER" Then
    Columns("P:AU").EntireColumn.Hidden = True
Else
    Columns("P:AU").EntireColumn.Hidden = False
End If

End Sub

I'm guessing to add the Match I will need something like this?

Sorry I haven't gotten down how else if works or need to add something?

Sub HideColumns()

If Range("O2").Text = "OTHER" Then Columns("P:AU").EntireColumn.Hidden = True

Elseif Range("O2").Text = "MATCH" Then Columns("P:BD").EntireColumn.Hidden = True

Else Columns("P:BD").EntireColumn.Hidden = False

EndIF

End Sub

Does this seem right?

Thanks Casey

Aucun commentaire:

Enregistrer un commentaire