![]() |
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 |
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 . |
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 . |
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 |
All times are GMT +1. The time now is 07:38 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com