Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If Condition


Hi,

I need to run a macro based on the contents of a cell, if cell A1
Apples, then
run macro1, if cell A1 = Oranges, then run macro2, etc.
Can anyone help.

Thanks


--
hlope
-----------------------------------------------------------------------
hlopes's Profile: http://www.excelforum.com/member.php...info&userid=75
View this thread: http://www.excelforum.com/showthread.php?threadid=26502

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default If Condition

There are two ways you can do this depending on your
preference

The first useses If...then elseif structure

dim fruit as text

fruit=worksheets("sheetname").Range("A1").value

If(fruit="Apples")
Macro1
elseif(fruit="Oranges")
Macro2
elseif(fruit="plums")
Macro3
etc...
end if

the second method would use the if structure only:

If(fruit="Apples")
Macro1
end if

if(fruit="Oranges")
Macro2
endi if

if(fruit="plums")
Macro3
end if

etc...

Both methods will accomplish what you want. These macros
would need to be in the project your working in. If not,
you would need a different method for calling the macro
that involves the Application.Run method. The syntax for
this method is more complicated, but if you need to do
this someone here can help. Just let us know.

Hope that helps!

Kevin
-----Original Message-----

Hi,

I need to run a macro based on the contents of a cell, if

cell A1 =
Apples, then
run macro1, if cell A1 = Oranges, then run macro2, etc.
Can anyone help.

Thanks



--
hlopes
----------------------------------------------------------

--------------
hlopes's Profile: http://www.excelforum.com/member.php?

action=getinfo&userid=755
View this thread:

http://www.excelforum.com/showthread...hreadid=265028

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default If Condition

hi,
a littl vague but...
you may need a third macro
sub whatif()
if range("A1").value = "Apples" then
call macro1
else
if Range("A1").value = "oranges" then
call macro 2
end if
end if
end sub
-----Original Message-----

Hi,

I need to run a macro based on the contents of a cell, if

cell A1 =
Apples, then
run macro1, if cell A1 = Oranges, then run macro2, etc.
Can anyone help.

Thanks



--
hlopes
----------------------------------------------------------

--------------
hlopes's Profile: http://www.excelforum.com/member.php?

action=getinfo&userid=755
View this thread:

http://www.excelforum.com/showthread...hreadid=265028

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default If Condition

select Case lcase(Range("A1"))
case "apples" : macro1
case "oranges" : macro2
case "pears" : macro3
end Select

--
Regards,
Tom Ogilvy

"hlopes" wrote in message
...

Hi,

I need to run a macro based on the contents of a cell, if cell A1 =
Apples, then
run macro1, if cell A1 = Oranges, then run macro2, etc.
Can anyone help.

Thanks



--
hlopes
------------------------------------------------------------------------
hlopes's Profile:

http://www.excelforum.com/member.php...nfo&userid=755
View this thread: http://www.excelforum.com/showthread...hreadid=265028



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
a few condition teratak Excel Worksheet Functions 7 May 3rd 08 03:56 PM
lookup with multiple condition, but one condition to satisfy is en Eddy Stan Excel Worksheet Functions 2 October 27th 07 02:06 PM
Combine an OR condition with an AND condition Will Excel Discussion (Misc queries) 1 April 6th 07 03:52 PM
Condition 1 overules condition 2? Bultgren Excel Worksheet Functions 2 January 20th 06 12:29 PM
Sum & IF condition John Excel Programming 1 August 20th 03 07:54 PM


All times are GMT +1. The time now is 03:39 PM.

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

About Us

"It's about Microsoft Excel"