ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA to say IF cell = any one of 3 values,then do something (https://www.excelbanter.com/excel-programming/397196-vba-say-if-cell-%3D-any-one-3-values-then-do-something.html)

PCLIVE

VBA to say IF cell = any one of 3 values,then do something
 
I'm drawing a blank on this one.

I need an IF statement in VBA that basically says, IF range("A1").value =
"name1" or "name2" or "Name3" then DoSomething.

The DoSomething code will be the same as long as A1 matches one of the three
names.
Any help?

Thanks,
Paul

--




JE McGimpsey

VBA to say IF cell = any one of 3 values,then do something
 
Simplest, perhaps:

With .Range("A1")
If (.Value) = "name1" Or (.Value = "name2") Or _
(.Value = "name3") Then
DoSomething
End If
End With


In article ,
"PCLIVE" wrote:

I'm drawing a blank on this one.

I need an IF statement in VBA that basically says, IF range("A1").value =
"name1" or "name2" or "Name3" then DoSomething.

The DoSomething code will be the same as long as A1 matches one of the three
names.
Any help?

Thanks,
Paul


Michael

VBA to say IF cell = any one of 3 values,then do something
 
If Range("A1").Value = "name1" Or Range("A1").Value = "name2" OR
Range("A1").Value = "name3" Then

Else

End If




If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"PCLIVE" wrote:

I'm drawing a blank on this one.

I need an IF statement in VBA that basically says, IF range("A1").value =
"name1" or "name2" or "Name3" then DoSomething.

The DoSomething code will be the same as long as A1 matches one of the three
names.
Any help?

Thanks,
Paul

--





Jim Thomlinson

VBA to say IF cell = any one of 3 values,then do something
 
A couple of possibles...

With Range("A1")
if .Value = "name1" or .Value = "name2" or .Value = "name2" then
'do something
end if

OR

Select Case Range("A1").Value
Case "name1", "name2", "name3"
'do Something
End Select
--
HTH...

Jim Thomlinson


"PCLIVE" wrote:

I'm drawing a blank on this one.

I need an IF statement in VBA that basically says, IF range("A1").value =
"name1" or "name2" or "Name3" then DoSomething.

The DoSomething code will be the same as long as A1 matches one of the three
names.
Any help?

Thanks,
Paul

--





Bill Renaud

VBA to say IF cell = any one of 3 values,then do something
 
If "Name1", "Name2", and "Name3" refer to named ranges ("Name1" refers
to cell $D$5, for example), then you might need something like the
following:

If Range("A1") = Range("Name1") Or _
Range("A1") = Range("Name2") Or _
Range("A1") = Range("Name3") _
Then
MsgBox "A1 is equal."
Else
MsgBox "A1 is not equal."
End If
--
Regards,
Bill Renaud




PCLIVE

VBA to say IF cell = any one of 3 values,then do something
 
Thanks JE,

I had to remove the period before "Range"...but other than that, it does the
trick.

Thanks again,
Paul


--

"JE McGimpsey" wrote in message
...
Simplest, perhaps:

With .Range("A1")
If (.Value) = "name1" Or (.Value = "name2") Or _
(.Value = "name3") Then
DoSomething
End If
End With


In article ,
"PCLIVE" wrote:

I'm drawing a blank on this one.

I need an IF statement in VBA that basically says, IF range("A1").value =
"name1" or "name2" or "Name3" then DoSomething.

The DoSomething code will be the same as long as A1 matches one of the
three
names.
Any help?

Thanks,
Paul




JE McGimpsey

VBA to say IF cell = any one of 3 values,then do something
 
Yup - artifact of testing. Glad it was obvious...

In article ,
"PCLIVE" wrote:

I had to remove the period before "Range"...but other than that, it does the
trick.


Jim Thomlinson

VBA to say IF cell = any one of 3 values,then do something
 
So you can't write an unqualified range even when testing... I thought it was
just me! :-)
--
HTH...

Jim Thomlinson


"JE McGimpsey" wrote:

Yup - artifact of testing. Glad it was obvious...

In article ,
"PCLIVE" wrote:

I had to remove the period before "Range"...but other than that, it does the
trick.



Dana DeLouis

VBA to say IF cell = any one of 3 values,then do something
 
Just different if the names do in fact follow a numbering pattern.

Sub Demo()
Select Case UCase([A1].Value)
Case "NAME1" To "NAME3"
MsgBox "Doing Something"
End Select
End Sub

--
Dana DeLouis


"PCLIVE" wrote in message
...
I'm drawing a blank on this one.

I need an IF statement in VBA that basically says, IF range("A1").value =
"name1" or "name2" or "Name3" then DoSomething.

The DoSomething code will be the same as long as A1 matches one of the
three names.
Any help?

Thanks,
Paul

--







All times are GMT +1. The time now is 09:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com