+ Reply to Thread
Results 1 to 2 of 2

Combining multiple macros into one

Hybrid View

  1. #1
    Registered User
    Join Date
    11-24-2011
    Location
    Chattanooga, TN
    MS-Off Ver
    Microsoft 365 MSO (Version 2303 Build 16.0.16227.20202) 64-bit
    Posts
    11

    Combining multiple macros into one

    I have a userform that has the same type information on 3 different entities (name, address, phone, etc). The same research is required on each one i.e. you need to look up the zip code for each). Therefore I have a bank of buttons on each page of the multipage form. Each button does the same thing depending on which page you are on. The following is my code to copy some information and open another application depending on which page you are on and which type entity.

    My question is how can I combine these into one so my module is not 3' long.

     Private Sub SUMRYButton1_Click()
    If Sheets("Info").Range("B197") = "BMF" Then
    Sheets("Info").Range("B208").Copy
    Else
    End If
    If Sheets("Info").Range("B197") = "IMF" Then
    Sheets("Info").Range("B223").Copy
    Else
    End If
    On Error GoTo EH
        ActivateWindow "attachmate"
        Exit Sub
    EH:
        MsgBox "IDRS is not open"
    End Sub
    Private Sub SUMRYButton2_Click()
    If Sheets("Info").Range("C197") = "BMF" Then
    Sheets("Info").Range("C208").Copy
    Else
    End If
    If Sheets("Info").Range("C197") = "IMF" Then
    Sheets("Info").Range("C223").Copy
    Else
    End If
    On Error GoTo EH
        ActivateWindow "attachmate"
        Exit Sub
    EH:
        MsgBox "IDRS is not open"
    End Sub
    Private Sub SUMRYButton3_Click()
    If Sheets("Info").Range("D197") = "BMF" Then
    Sheets("Info").Range("D208").Copy
    Else
    End If
    If Sheets("Info").Range("D197") = "IMF" Then
    Sheets("Info").Range("D223").Copy
    Else
    End If
    On Error GoTo EH
        ActivateWindow "attachmate"
        Exit Sub
    EH:
        MsgBox "IDRS is not open"
    End Sub

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Combining multiple macros into one

    Private Sub SUMRYButton1_Click()
       CheckIDRS
    End Sub
    Private Sub SUMRYButton2_Click()
       CheckIDRS
    End Sub
    Private Sub SUMRYButton3_Click()
       CheckIDRS
    End Sub
    
    Sub CheckIDRS()
    If Sheets("Info").Range("D197") = "BMF" Then
    Sheets("Info").Range("D208").Copy
    Else
    End If
    If Sheets("Info").Range("D197") = "IMF" Then
    Sheets("Info").Range("D223").Copy
    Else
    End If
    On Error GoTo EH
        ActivateWindow "attachmate"
        Exit Sub
    EH:
        MsgBox "IDRS is not open"
    End Sub
    David
    (*) Reputation points appreciated.

+ 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. [SOLVED] Combining Multiple Macros into One
    By pinstripe05 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-07-2013, 03:06 AM
  2. Combining multiple macros into one
    By strder1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-11-2012, 08:51 AM
  3. Combining multiple macros into one subroutine
    By Quentyn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2011, 05:48 PM
  4. Combining Multiple Macros
    By ZEvans12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2011, 01:39 PM
  5. Combining Multiple Macros
    By Brenda42 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-05-2011, 09:50 AM

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