Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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
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
Calculate times between dates and times in Excel Helio Excel Discussion (Misc queries) 1 March 25th 10 04:29 AM
count text appear how many times & put in respec col??eg 1st times Piglet Excel Discussion (Misc queries) 3 May 29th 08 07:53 AM
Calculation of hourly rate times hours times 1.5 Newbusinessbod Excel Worksheet Functions 1 December 6th 05 04:44 PM
How are relay leg times or driving times entered and totaled? commissioner Excel Worksheet Functions 1 July 26th 05 09:27 PM
Charting and analyzing Times' times data for trends Johnny Excel Discussion (Misc queries) 1 May 5th 05 01:36 AM


All times are GMT +1. The time now is 09:09 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"