+ Reply to Thread
Results 1 to 4 of 4

Issue Trying To Autorun Macro

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Issue Trying To Autorun Macro

    I have my macro, already created
    Sub ConsolidateDestroyData()
     Dim ws As Worksheet, wsMaster As Worksheet, LR As Long
     Application.ScreenUpdating = 0
     Set wsMaster = Sheets("Destroy")
     wsMaster.UsedRange.Offset.Clear
     For Each ws In ThisWorkbook.Worksheets
     With ws
        If .Name <> wsMaster.Name And .Name <> "Live" And .Name <> "Data" And .Name <> "Totals" Then
            .AutoFilterMode = False
                If .Range("H2") <> vbNullString Then
                .Rows(1).AutoFilter 8, "1"
                LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
                If LR > 1 Then
                    .Range("A2:G" & LR).Copy
                    wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
                    End If
                    .Rows(1).AutoFilter
                End If
            End If
        End With
     Next ws
    
     Application.ScreenUpdating = True
     End Sub
    I've now decided I want to autorun this macro on opening the workbook. When I add
    Private Sub Workbook_Open()
    at the beginning it returns an error.

    How and where do I add this command?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Issue Trying To Autorun Macro

    In the ThisWorkbook module of your workbook:

    Private Sub Workbook_Open()
    Call ConsolidateDestroyData
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Issue Trying To Autorun Macro

    Quote Originally Posted by romperstomper View Post
    In the ThisWorkbook module of your workbook:

    Private Sub Workbook_Open()
    Call ConsolidateDestroyData
    End Sub
    That works great, thanks. What if I had more than one macro in the same workbook that I wanted to autorun at start?

  4. #4
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Issue Trying To Autorun Macro

    Never mind, I've answered my own question now.

    Thanks for your help.

+ 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. Autorun macro
    By Greed in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2012, 10:21 AM
  2. autorun a macro
    By Smudge in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-11-2006, 08:25 AM
  3. [SOLVED] Autorun macro
    By Kelly in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-18-2006, 12:10 PM
  4. MACRO AUTORUN
    By b52shut in forum Excel General
    Replies: 1
    Last Post: 12-15-2005, 04:55 AM
  5. Autorun a macro
    By Paul Wisken in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-07-2005, 03:05 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