![]() |
call macro X by cell value
First off, this is my first post on this site and i'm excited. I've use another site for years and recently i thought of looking at other sites and talk about a sign or something; after registering the first topic saw was the exact topic i was working on! WOW --- I think i've come t the right place!!!!!!!!!! so here we go how would i adapt this code ================================================== ========== If [s6].Value = 1 Then Call addMC If [r6].Value = 1 Then Call addJar If [q6].Value = 1 Then Call add2oz If [p6].Value = 1 Then Call add8oz If [o6].Value = 1 Then Call add18oz If [n6].Value = 1 Then Call add32oz ================================================== ========= so that the macros that are called are run as many times as the valu in their respective cells. Example: for the first line "If [s6].Value = 1 Then Call addMC" if cel S6 = 12 then the Macro AddMC will be run 12 times and if cell S6 = then the macro would only me run twice or even if S6 = 0 then the macr would not be run. I think i've made my point. As you can see there i more then 2 or so seperate macros their respective cells to run ever time this sub is run. Thanks Edit/Delete Messag -- cyote10 ----------------------------------------------------------------------- cyote101's Profile: http://www.excelforum.com/member.php...fo&userid=3614 View this thread: http://www.excelforum.com/showthread.php?threadid=55921 |
call macro X by cell value
Assuming this code will be called from the Worksheet_Change event:
Private Sub Worksheet_Change(ByVal Target As Range) Dim i As Long Dim MacroName As string Select Case Target.Address Case "$N$6" MacroName = "add32oz" Case "$Q$6" MacroName = "add2oz" ...etc Case Else Exit sub End select For i=1 To Target.Value Application.Run MacroName Next End Sub NickHK "cyote101" wrote in message ... First off, this is my first post on this site and i'm excited. I've used another site for years and recently i thought of looking at other sites- and talk about a sign or something; after registering the first topic i saw was the exact topic i was working on! WOW --- I think i've come to the right place!!!!!!!!!! so here we go how would i adapt this code ================================================== ========== If [s6].Value = 1 Then Call addMC If [r6].Value = 1 Then Call addJar If [q6].Value = 1 Then Call add2oz If [p6].Value = 1 Then Call add8oz If [o6].Value = 1 Then Call add18oz If [n6].Value = 1 Then Call add32oz ================================================== ========= so that the macros that are called are run as many times as the value in their respective cells. Example: for the first line "If [s6].Value = 1 Then Call addMC" if cell S6 = 12 then the Macro AddMC will be run 12 times and if cell S6 = 2 then the macro would only me run twice or even if S6 = 0 then the macro would not be run. I think i've made my point. As you can see there is more then 2 or so seperate macros their respective cells to run every time this sub is run. Thanks Edit/Delete Message -- cyote101 ------------------------------------------------------------------------ cyote101's Profile: http://www.excelforum.com/member.php...o&userid=36145 View this thread: http://www.excelforum.com/showthread...hreadid=559211 |
call macro X by cell value
dim iCtr as long
with activesheet if isnumeric(.range("s6").value) then for ictr = 1 to .range("s6").value call addMC next ictr end if ....and more stuff like that.... end with cyote101 wrote: First off, this is my first post on this site and i'm excited. I've used another site for years and recently i thought of looking at other sites- and talk about a sign or something; after registering the first topic i saw was the exact topic i was working on! WOW --- I think i've come to the right place!!!!!!!!!! so here we go how would i adapt this code ================================================== ========== If [s6].Value = 1 Then Call addMC If [r6].Value = 1 Then Call addJar If [q6].Value = 1 Then Call add2oz If [p6].Value = 1 Then Call add8oz If [o6].Value = 1 Then Call add18oz If [n6].Value = 1 Then Call add32oz ================================================== ========= so that the macros that are called are run as many times as the value in their respective cells. Example: for the first line "If [s6].Value = 1 Then Call addMC" if cell S6 = 12 then the Macro AddMC will be run 12 times and if cell S6 = 2 then the macro would only me run twice or even if S6 = 0 then the macro would not be run. I think i've made my point. As you can see there is more then 2 or so seperate macros their respective cells to run every time this sub is run. Thanks Edit/Delete Message -- cyote101 ------------------------------------------------------------------------ cyote101's Profile: http://www.excelforum.com/member.php...o&userid=36145 View this thread: http://www.excelforum.com/showthread...hreadid=559211 -- Dave Peterson |
call macro X by cell value
well thank you for your help, I actually need a code for a macro, so itcan be used onlywhen it's need not all the time. buti think thats the trick. so howdo i make it into a macro, this is whati have so far ================================================== ======== Sub Createpack() Dim i As Long Dim MacroName As String Select Case Target.Address Case "$s$6" MacroName = "addmc" Case "$r$6" MacroName = "addjar" Case "$q$6" MacroName = "add2oz" Case "$p$6" MacroName = "add8oz" Case "$o$6" MacroName = "add18oz" Case "$n$6" MacroName = "add32oz" Case Else Exit Sub -- cyote101 ------------------------------------------------------------------------ cyote101's Profile: http://www.excelforum.com/member.php...o&userid=36145 View this thread: http://www.excelforum.com/showthread...hreadid=559211 |
call macro X by cell value
You may want to explain more about when you want this code to run and how it
should be started. cyote101 wrote: well thank you for your help, I actually need a code for a macro, so itcan be used onlywhen it's need not all the time. buti think thats the trick. so howdo i make it into a macro, this is whati have so far ================================================== ======== Sub Createpack() Dim i As Long Dim MacroName As String Select Case Target.Address Case "$s$6" MacroName = "addmc" Case "$r$6" MacroName = "addjar" Case "$q$6" MacroName = "add2oz" Case "$p$6" MacroName = "add8oz" Case "$o$6" MacroName = "add18oz" Case "$n$6" MacroName = "add32oz" Case Else Exit Sub -- cyote101 ------------------------------------------------------------------------ cyote101's Profile: http://www.excelforum.com/member.php...o&userid=36145 View this thread: http://www.excelforum.com/showthread...hreadid=559211 -- Dave Peterson |
All times are GMT +1. The time now is 05:05 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com