Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
If then several times
I seem to be having a problem running a macro that uses several if then
statements. Here is an example... why won't the second third, fourth if statements run? If Activecell.value = 1 then DO whatever end if If activecell.value =2 then do whatever end if Ifactivecell.value = 3 then do whatever end if end sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
If then several times
What do you mean by "why won't...if statements run?" Do you mean they
are not evaluated? Or that the 'do whatever' part is not executed? What is the value of the active cell? What does the first 'DO whatever' actually contain? -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , says... I seem to be having a problem running a macro that uses several if then statements. Here is an example... why won't the second third, fourth if statements run? If Activecell.value = 1 then DO whatever end if If activecell.value =2 then do whatever end if Ifactivecell.value = 3 then do whatever end if end sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
If then several times
The "activecell.value" had text and only worked when I matched the case of
the letters in the text..., I thought that didn't matter, but apparently it does. Sorry and thanks again... "Tushar Mehta" wrote: What do you mean by "why won't...if statements run?" Do you mean they are not evaluated? Or that the 'do whatever' part is not executed? What is the value of the active cell? What does the first 'DO whatever' actually contain? -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , says... I seem to be having a problem running a macro that uses several if then statements. Here is an example... why won't the second third, fourth if statements run? If Activecell.value = 1 then DO whatever end if If activecell.value =2 then do whatever end if Ifactivecell.value = 3 then do whatever end if end sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
If then several times
If your code is embedded in a procedure or function, and the "d
whatever" has an "exit sub" line in it, then it won't proces anything else that follows it in that section of code You're also better off using a Case structure, or throwin activecell.value into a variable so you don't repeatedly retrieve th same information over and over and over.. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
If then several times
there is no "exit sub" in the code... however, your suggestion about seeting
variables is a good one. Thanks "leaftye - ExcelForums.com" wrote: If your code is embedded in a procedure or function, and the "do whatever" has an "exit sub" line in it, then it won't process anything else that follows it in that section of code. You're also better off using a Case structure, or throwing activecell.value into a variable so you don't repeatedly retrieve the same information over and over and over... |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
If then several times
What is "case structure"?
"leaftye - ExcelForums.com" wrote: If your code is embedded in a procedure or function, and the "do whatever" has an "exit sub" line in it, then it won't process anything else that follows it in that section of code. You're also better off using a Case structure, or throwing activecell.value into a variable so you don't repeatedly retrieve the same information over and over and over... |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
If then several times
I think he means:
Select Case "ActiveValue" Case 1 'code goes here Case 2 'code goes here Case 3 'code goes here Case Else ' Incorrect value. 'code goes here End Select |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Calculate times between dates and times in Excel | Excel Discussion (Misc queries) | |||
count text appear how many times & put in respec col??eg 1st times | Excel Discussion (Misc queries) | |||
Calculation of hourly rate times hours times 1.5 | Excel Worksheet Functions | |||
How are relay leg times or driving times entered and totaled? | Excel Worksheet Functions | |||
Charting and analyzing Times' times data for trends | Excel Discussion (Misc queries) |