+ Reply to Thread
Results 1 to 2 of 2

What goes between 2 macros so one runs right after the first?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-02-2012
    Location
    Florida
    MS-Off Ver
    Home -Excel 2007, Work 2016
    Posts
    254

    What goes between 2 macros so one runs right after the first?

    Sub test()
    Dim LR&, r&
    LR = Range("A" & Rows.Count).End(xlUp).Row
    For r = 8 To LR: Cells(r, 1) = "." & Cells(r, 1).Value & ".": Next
    End Sub
    
    Sub test()
    On Error Resume Next
    For Each r In Range("b8:b" & Cells(Rows.Count, 2).End(xlUp).Row)
        With Columns(1)
            Set c = .Find(r.Value, , , 2)
                If Not c Is Nothing Then
                    f = c.Address
                    Do
                        c.Value = Replace(c.Value, r.Value, r.Offset(, 1).Value)
                    Set c = .FindNext(c)
                    Loop Until f = c.Address
                End If
        End With
    Next
    End Sub
    Last edited by ILoveStMartin; 11-08-2012 at 01:09 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: What goes between 2 macros so one runs right after the first?

    You cannot have the two macros named the same (test).

    You could combine the two macros in to one macro or you can create a third macro that runs the two other macros e.g.;
    Sub Run_Two_Macros()
        Call Test1
        Call Test2
    End Sub
    This runs the two macros Test1 and Test2.

    Or you could call the 2nd macro at the end of the first macro...
    Sub Test1()
        Dim LR&, r&
        LR = Range("A" & Rows.Count).End(xlUp).Row
        For r = 8 To LR: Cells(r, 1) = "." & Cells(r, 1).Value & ".": Next
        Call Test2
    End Sub
        
    Sub Test2()
    On Error Resume Next
    For Each r In Range("b8:b" & Cells(Rows.Count, 2).End(xlUp).Row)
        With Columns(1)
            Set c = .Find(r.Value, , , 2)
                If Not c Is Nothing Then
                    f = c.Address
                    Do
                        c.Value = Replace(c.Value, r.Value, r.Offset(, 1).Value)
                    Set c = .FindNext(c)
                    Loop Until f = c.Address
                End If
        End With
    Next
    End Sub
    Last edited by AlphaFrog; 11-08-2012 at 01:36 AM.

+ 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