+ Reply to Thread
Results 1 to 5 of 5

Call Only a Defined Number of Macros based on cell Value

Hybrid View

qexcel2 Call Only a Defined Number of... 01-19-2023, 01:07 PM
ByteMarks Re: Call Only a Defined... 01-19-2023, 01:20 PM
Mumps1 Re: Call Only a Defined... 01-19-2023, 01:21 PM
qexcel2 Re: Call Only a Defined... 01-19-2023, 01:31 PM
Mumps1 Re: Call Only a Defined... 01-19-2023, 02:10 PM
  1. #1
    Registered User
    Join Date
    12-28-2022
    Location
    Canada
    MS-Off Ver
    2021
    Posts
    55

    Call Only a Defined Number of Macros based on cell Value

    Hi,
    I have this code which calls other macros. I want that I would write a value say 4 in cell P1. Then this code Sub All_In_One should only call first 4 macros i.e till Macro no.4. It should not call Macro5, Macro6 and Macro7.
    Sub All_In_One()
    Call Macro1
    Call Macro2
    Call Macro3
    Call Macro4
    Call Macro5
    Call Macro6
    Call Macro7
    End Sub
    Many Thanks

  2. #2
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,119

    Re: Call Only a Defined Number of Macros based on cell Value

    Maybe something like this.

    Sub All_In_One()
    Dim i As Integer, iMax As Integer
    
    On Error Resume Next
    iMax = [P4].Value
    On Error GoTo 0
    
    Select Case iMax
        Case 1 To 7
            For i = 1 To iMax
                Application.Run "Macro" & i
            Next
    End Select
    End Sub

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,056

    Re: Call Only a Defined Number of Macros based on cell Value

    Try:
    Sub All_In_One()
        Dim x As Long: x = 1
        Call Macro1
        MsgBox x
        If Range("P1") = x Then Exit Sub
        x = x + 1
        Call Macro2
        If Range("P1") = x Then Exit Sub
        x = x + 1
        Call Macro3
        If Range("P1") = x Then Exit Sub
        x = x + 1
        Call Macro4
        If Range("P1") = x Then Exit Sub
        x = x + 1
        Call Macro5
        If Range("P1") = x Then Exit Sub
        x = x + 1
        Call Macro6
        If Range("P1") = x Then Exit Sub
        x = x + 1
        Call Macro7
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  4. #4
    Registered User
    Join Date
    12-28-2022
    Location
    Canada
    MS-Off Ver
    2021
    Posts
    55

    Re: Call Only a Defined Number of Macros based on cell Value

    Hi Sir Mumps1,
    Thank you so much. It worked perfectly
    Many Thanks

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,056

    Re: Call Only a Defined Number of Macros based on cell Value

    You are very welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Return a cell based on a defined array and indexed number
    By Challiss in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-19-2021, 12:16 AM
  2. [SOLVED] Call Different Macros Based on Value in Single Cell
    By aglawrence in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2018, 02:18 PM
  3. Replies: 1
    Last Post: 10-03-2017, 10:54 AM
  4. [SOLVED] Confusing problem: Retrieving cell values based on user defined number range.
    By Andee in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-02-2014, 10:43 AM
  5. Replies: 8
    Last Post: 02-21-2013, 05:16 PM
  6. Macro to Call/Run Other Macros Based on Conditions
    By ExcelGuy160 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-20-2010, 06:18 PM
  7. [SOLVED] How to call a sub defined in macro when double click a cell?
    By Ivan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-20-2005, 05:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1