Jump to content

Guide about if..Endif - (Moved)


Recommended Posts

Hello Guys Can you lead me how to simplified this? :sweating:

Thanks, ^_^

 

Sub 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

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

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

mmhmmm u can Use the call function..

I will give u the switch eggsample:D

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

 

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

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 by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

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 by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • Moderators
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

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

  • Moderators

Happens to us all @ajag 

I have to stop going by number of posts, have done that a couple of times :)

 

Edited 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

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...