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