Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLookup multiple values - sum returned values into single cell se7098 Excel Worksheet Functions 12 April 2nd 23 07:32 PM
Copy values from a cell based on values of another cell Spence10169 Excel Discussion (Misc queries) 4 January 13th 09 10:01 AM
How to assign values to a cell based on values in another cell? Joao Lopes Excel Worksheet Functions 1 December 5th 07 09:02 PM
Search/Filter to find values in another range based on two cell values Andy Excel Programming 2 April 29th 04 04:08 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"