Results 1 to 6 of 6

Running macro across multiple worksheets

Threaded View

  1. #1
    Registered User
    Join Date
    11-17-2014
    Location
    Hartford, CT
    MS-Off Ver
    Excel 2010
    Posts
    7

    Running macro across multiple worksheets

    Hi there,
    I am currently running this macro and wanted to run it for multiple worksheets in the same workbook. Wanted to have this work for multiple worksheets in the workbook and not just one.
    Thanks in advance.

    Sub parse_data()

    Dim lr As Long
    Dim ws As Worksheet
    Dim vcol, i As Integer
    Dim icol As Long
    Dim myarr As Variant
    Dim title As String
    Dim titlerow As Integer
    vcol = 3
    Set ws = Sheets("Sheet1")
    lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
    title = "A2:O2"
    titlerow = ws.Range(title).Cells(1).Row
    icol = ws.Columns.Count
    ws.Cells(1, icol) = "Unique"
    For i = 2 To lr
    On Error Resume Next
    If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
    ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
    End If
    Next

    myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
    ws.Columns(icol).Clear
    For i = 2 To UBound(myarr)
    ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
    If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
    Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
    Else
    Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
    End If
    ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
    Sheets(myarr(i) & "").Columns.AutoFit
    Next
    ws.AutoFilterMode = False
    ws.Activate
    End Sub

    Any thoughts?
    Last edited by pswiatek; 11-17-2014 at 01:45 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Running a single macro in multiple worksheets
    By robinson032 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-06-2014, 01:54 PM
  2. Running Macro through multiple worksheets
    By ALexcell47 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2012, 08:52 PM
  3. Running Macros on multiple worksheets
    By shivrklfc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2012, 11:11 AM
  4. Running One Macro in Multiple Worksheets & Loop
    By mjali001 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-10-2011, 04:57 PM
  5. Running Macro/VBA in multiple worksheets.
    By YellowBird in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-09-2006, 12:30 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