Ilounah Posted July 15, 2018 Share Posted July 15, 2018 Hello Guys Can you lead me how to simplified this? Thanks, expandcollapse popupSub LoadData() Application.ScreenUpdating = False Sleep 2000 Application.StatusBar = "CreateData" If Worksheets("K-PMIXc").Range("C12").Value = "Calc01" Then Call Calc01 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc02" Then Call Calc02 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc03" Then Call Calc03 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc04" Then Call Calc04 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc05" Then Call Calc05 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc06" Then Call Calc06 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc07" Then Call Calc07 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc08" Then Call Calc08 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc09" Then Call Calc09 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc10" Then Call Calc10 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc11" Then Call Calc11 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc12" Then Call Calc12 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc13" Then Call Calc13 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc14" Then Call Calc14 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc15" Then Call Calc15 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc16" Then Call Calc16 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc17" Then Call Calc17 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc18" Then Call Calc18 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc19" Then Call Calc19 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc20" Then Call Calc20 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc21" Then Call Calc21 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc22" Then Call Calc22 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc23" Then Call Calc23 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc24" Then Call Calc24 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc25" Then Call Calc25 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc26" Then Call Calc26 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc27" Then Call Calc27 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc28" Then Call Calc28 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc29" Then Call Calc29 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc30" Then Call Calc30 End If If Worksheets("K-PMIXc").Range("C12").Value = "Calc31" Then Call Calc31 End If Application.ScreenUpdating = True End Sub Link to comment Share on other sites More sharing options...
Surya Posted July 15, 2018 Share Posted July 15, 2018 U don't have to use if always use else if like this If Worksheets("K-PMIXc").Range("C12").Value = "Calc01" Then Call Calc01 elseif Worksheets("K-PMIXc").Range("C12").Value = "Calc02" Then Call Calc02 ;----- End If or use switch case like Switch Worksheets("K-PMIXc").Range("C12").Value Case "Calc01" Call Calc01 Break Case "Calc02" Call Calc02 ;.. ;... ;... EndSwitch Or use ternary operators Ilounah 1 No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
Ilounah Posted July 15, 2018 Author Share Posted July 15, 2018 I Don't know if this is possible, Can I use Cell Value to replace the name to Call Macro. ex. Call Range("B12").value ? Link to comment Share on other sites More sharing options...
Surya Posted July 15, 2018 Share Posted July 15, 2018 mmhmmm u can Use the call function.. I will give u the switch eggsample Local $range = Worksheets("K-PMIXc").Range("C12").Value Switch $range Case "Calc01" Call($range) Break Case "Calc02" Call($range) ;.. ;... ;... EndSwitch ;-read the helpfile to know more about call function Ilounah 1 No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
Ilounah Posted July 15, 2018 Author Share Posted July 15, 2018 @Surya, Sorry I was referring to vba code, I think this code is for Autoit Link to comment Share on other sites More sharing options...
Earthshine Posted July 15, 2018 Share Posted July 15, 2018 (edited) https://www.techonthenet.com/excel/formulas/case.php Convert it to this structure Select Case test_expression Case condition_1 result_1 Case condition_2 result_2 ... Case condition_n result_n [ Case Else result_else ] End Select Edited July 16, 2018 by Earthshine Ilounah 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 16, 2018 Moderators Share Posted July 16, 2018 Moved to the appropriate forum. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Earthshine Posted July 16, 2018 Share Posted July 16, 2018 (edited) Sub Macro1() Select Case Worksheets("Sheet1").Range("C12").Value Case "Calc20" Calc20 Case "Calc21" ' Calc21 Case "Calcnn" ' CalcNN Case Else MsgBox "ERROR, THE SKY IS FALLING! -- Chicken Little" End Select End Sub Sub Calc20() MsgBox "Hey! Calc20 Reporting!!" End Sub I tested it in latest Office365, works. Edited July 16, 2018 by Earthshine Ilounah 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 16, 2018 Share Posted July 16, 2018 On 15/7/2018 at 5:11 PM, Surya said: Case "Calc01" Call($range) Break Wacth out at the use of Break! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
ajag Posted July 17, 2018 Share Posted July 17, 2018 Dim $func = Worksheets("Sheet1").Range("C12").Value Call ($func) Earthshine 1 Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
Earthshine Posted July 17, 2018 Share Posted July 17, 2018 (edited) she wants vba code. can't read? Edited July 17, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
ajag Posted July 17, 2018 Share Posted July 17, 2018 25 minutes ago, Earthshine said: she wants vba code. can't read? ooops, sorry! Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 17, 2018 Moderators Share Posted July 17, 2018 54 minutes ago, Earthshine said: she wants vba code. can't read? Someone new trying to help made a mistake, can't be decent? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
ajag Posted July 17, 2018 Share Posted July 17, 2018 26 minutes ago, JLogan3o13 said: Someone new trying to help made a mistake, can't be decent? No problem. BTW: Earthshine joined Sep 28, 2017 ajag joined Oct 22, 2008 ;-) just over-read the VBA thing. Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 17, 2018 Moderators Share Posted July 17, 2018 (edited) Happens to us all @ajag I have to stop going by number of posts, have done that a couple of times Edited July 17, 2018 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Earthshine Posted July 17, 2018 Share Posted July 17, 2018 (edited) ooops, sorry! sorry guys. I'll have some coffee and be betterer Edited July 17, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Ilounah Posted July 28, 2018 Author Share Posted July 28, 2018 My Inventory Form is working now, Thanks for new ideas Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now