+ Reply to Thread
Results 1 to 4 of 4

How can you run a macro in multiple sheets (same workbook) at once???

Hybrid View

  1. #1
    Registered User
    Join Date
    06-07-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2010
    Posts
    72

    How can you run a macro in multiple sheets (same workbook) at once???

    Need to do this...

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: How can you run a macro in multiple sheets (same workbook) at once???

    Loop through them

    Dim ws As Worksheet
    For Each ws In Worksheets
        MsgBox ws.Name
    Next

  3. #3
    Registered User
    Join Date
    06-07-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: How can you run a macro in multiple sheets (same workbook) at once???

    Quote Originally Posted by jason.b75 View Post
    Loop through them

    Dim ws As Worksheet
    For Each ws In Worksheets
        MsgBox ws.Name
    Next
    Fantastic, thanks. How do I combine this with a macri I already have?
    I have this:
    Sub DeleteRows()
        Range("A2").Select
        Do Until ActiveCell.Value = ""
            If ActiveCell.Value <> "Art" Then
                ActiveCell.EntireRow.Delete
            Else
                ActiveCell.Offset(1, 0).Select
            End If
        Loop
    End Sub

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: How can you run a macro in multiple sheets (same workbook) at once???

    A slightly different method, this does the whole sheet at once instead of one row at a time.

    Sub DeleteRows()
    Dim ws As Worksheet, c As Range
    For Each ws In Worksheets
        With ws.UsedRange
            .AutoFilter , Field:=1, Criteria1:="<>art"
            .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        End With
    ws.AutoFilterMode = False
    Next
    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