+ Reply to Thread
Results 1 to 3 of 3

Macro to run macros from different worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    Charlote, NC
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro to run macros from different worksheets

    I need a macro that I can assign to a button on the first of four worksheets, that will run a specific macro I've written for each of the 3 other worksheets. I tried writing a macro that called each of the other macros I needed, but it ran all of them on sheet 2. I need it to call and run macro 2 on sheet 2 only, macro 3 on sheet 3 only, etc. Coding for each macro to a specific sheet is in the general form below.

    Sub SectionB_Add_Loan()
    '
    ' Adds additional loan to Section B
    '
        Columns("F:F").Select
        Selection.Copy
        Selection.Insert Shift:=xlToRight
        Application.CutCopyMode = False
        
        Dim lLastCol As Long
        
        lLastCol = ((Sheet4.UsedRange.Column + _
                     Sheet4.UsedRange.Columns.Count) - 47)
        
        With Sheet4
            .Range("D4:E4").AutoFill .Range( _
                    .Cells(4, 4), .Cells(4, lLastCol)), xlFillDefault
        End With
    End Sub
    Last edited by rcarder1; 11-01-2012 at 09:31 AM. Reason: conform to forum rules

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,937

    Re: Write macro to run a macro on several different sheets

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.



    Also, your explanation is unclear.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    10-23-2012
    Location
    Charlote, NC
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro to run macros from different worksheets

    Sorry about that. Hopefully this fixes it.

    I need a macro that I can assign to a button on the first of four worksheets, that will run a specific macro I've written for each of the 3 other worksheets. I tried writing a macro that called each of the other macros I needed, but it ran all of them on sheet 2. I need it to call and run macro 2 on sheet 2 only, macro 3 on sheet 3 only, etc. Coding for each macro to a specific sheet is in the general form below.

    Sub SectionB_Add_Loan()
    '
    ' Adds additional loan to Section B
    '
    Columns("F:F").Select
    Selection.Copy
    Selection.Insert Shift:=xlToRight
    Application.CutCopyMode = False
    
    Dim lLastCol As Long
    
    lLastCol = ((Sheet4.UsedRange.Column + _
    Sheet4.UsedRange.Columns.Count) - 47)
    
    With Sheet4
    .Range("D4:E4").AutoFill .Range( _
    .Cells(4, 4), .Cells(4, lLastCol)), xlFillDefault
    End With
    End Sub .

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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