if target.column = 1 or 2 or 3 ? Help !


Posted by Phil Ridley on February 03, 2002 7:23 PM

Hi all,
I have a macro where I am using an if statement to execute functions on cells in certain columns. I need to know how to phrase the multiple choice "IF" statement (if target.column = 1 or 2 or 3 ?)

any help would be appreciated.

Phil.

Posted by Tom Urtis on February 03, 2002 7:55 PM

If Target.Column < 4 Then (nt)

Posted by Phil Ridley on February 03, 2002 9:31 PM

What about target.column= 6 or 9 or 11 ?

The or statement seems only to work for the last value in the range.

Posted by Bariloche on February 03, 2002 9:58 PM

Re: What about target.column= 6 or 9 or 11 ?

Phil,

If you are doing slightly different things to the various coulmns, you might want to use a Select Case statement. Then you can list all your columns:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Select Case Target.Column

Case Is = 3
MsgBox "You're in column 3"

Case Is = 1, 2, 4
MsgBox "You're in column " & Target.Column

Case Is >= 5
MsgBox "You're in column " & Target.Column

End Select

End Sub

have fun



Posted by Phil Ridley on February 03, 2002 10:38 PM

Excellent. Thank you ! n/t

Case Is = 3 MsgBox "You're in column 3" Case Is = 1, 2, 4 MsgBox "You're in column " & Target.Column Case Is >= 5 MsgBox "You're in column " & Target.Column End Select

: The or statement seems only to work for the last value in the range.