Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 -- |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 -- |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 -- |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 -- |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VLookup multiple values - sum returned values into single cell | Excel Worksheet Functions | |||
Copy values from a cell based on values of another cell | Excel Discussion (Misc queries) | |||
How to assign values to a cell based on values in another cell? | Excel Worksheet Functions | |||
Search/Filter to find values in another range based on two cell values | Excel Programming |