Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Is it possible to choose a macro based upon a valve of a variable??

I have written 6 macros and want to choose to use 1 of them depending upon
the value of “n” in cell A1

If “n” = 1 through 20 use Macro 1
If “n” = 21 through 40 use Macro 2
If “n” = 41 through 60 use Macro 3
If “n” = 61 through 80 use Macro 4
If “n” = 81 through 100 use Macro 5
If “n” = 100 use Macro 6

Is this possible??


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Is it possible to choose a macro based upon a valve of a variable??

use a case statement

Select case n
case 1 to 20
macro1
case 21 to 40
macro2


End Select

--
Regards,
Tom Ogilvy

"Rob947" wrote in message
lkaboutsoftware.com...
I have written 6 macros and want to choose to use 1 of them depending upon
the value of "n" in cell A1

If "n" = 1 through 20 use Macro 1
If "n" = 21 through 40 use Macro 2
If "n" = 41 through 60 use Macro 3
If "n" = 61 through 80 use Macro 4
If "n" = 81 through 100 use Macro 5
If "n" = 100 use Macro 6

Is this possible??




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Is it possible to choose a macro based upon a valve of a variable??


You practically have the code written already.

Sub RunMacro()
If n <= 20 Then Macro1
If n = 21 And n <= 40 Then Macro2
If n = 41 And n <= 60 Then Macro3
If n = 61 And n <= 80 Then Macro4
If n = 81 And n <= 100 Then Macro 5
If n = 101 Then Macro6
End Sub

If you expect non integer values for n then you will want to replace
either the less than or equal to, or the greater than or equal to in
each If statement to simply less than, or greater than (depending on
how you want the variable treated).

HTH


--
bhofsetz
------------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...o&userid=18807
View this thread: http://www.excelforum.com/showthread...hreadid=375284

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
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
listing values to choose from based on value in another cell MT Excel Discussion (Misc queries) 1 September 12th 05 01:37 PM
Choose data from a particular column based on a specific value markx Excel Worksheet Functions 1 July 15th 05 06:55 PM
Run MACRO from the valve of a cell? FX Boudreaux Excel Programming 2 August 12th 04 08:07 AM
How to pass valve in combobox object to cell chanon Excel Programming 3 October 15th 03 04:25 AM


All times are GMT +1. The time now is 04:10 AM.

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"