+ Reply to Thread
Results 1 to 4 of 4

Running Macro Across Multiple Sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    3

    Running Macro Across Multiple Sheets

    Hi,

    I have a macro on the attached workbook that looks at one of the "Draft" sheets and runs the macro to look through the individual team tabs and returns what you see in Draft20 in Column F and G (if that player is in one of the tabs, that information from the tabs he's in).

    In the past, I have just been manually moving each individual draft tab to the first tab in the workbook and then running the macro with the name of the sheet in it but is there some way I can just run all my draft tabs all at once?

    Hopefully it's an easy solution.

    (Skimmed down the draft tabs to comply with the rules of the forum)

    Thanks for the help.

  2. #2
    Registered User
    Join Date
    08-15-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    9

    Re: Running Macro Across Multiple Sheets

    Without changing too much of your code, try the attached with updated "Draft" macro.

    This will update all the sheets with the name "Draft" in them.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,693

    Re: Running Macro Across Multiple Sheets

    Try
    Sub Maybe()
    Dim a As Long, i As Long, j As Long
    For a = 1 To 6
        For i = 2 To Sheets(a).Cells(Sheets(a).Rows.Count, 5).End(xlUp).Row
            For j = 7 To ThisWorkbook.Sheets.Count
                If Application.WorksheetFunction.CountIf(Sheets(j).UsedRange, Sheets(a).Cells(i, 5).Value) > 0 Then
                    Sheets(a).Cells(i, 5).Offset(, 1).Value = Sheets(j).Range("A1").Value
                    Sheets(a).Cells(i, 5).Offset(, 2).Value = Sheets(j).Cells(Sheets(j).UsedRange.Find(Sheets(a).Cells(i, 5).Value).Row, 1).Value
                    Exit For
                End If
            Next j
        Next i
    Next a
    End Sub

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Running Macro Across Multiple Sheets

    Are you trying to do like this?
    Order of the worksheets doesn't matter.
    Sub Draft()
        Dim ws As Worksheet, sh As Worksheet
        Dim player As String, team As String
        Dim r As Range, c As Range
        For Each ws In Worksheets
            If ws.Name Like "Draft#*" Then
                For Each r In ws.Range("e2", ws.Range("e" & Rows.Count).End(xlUp))
                    player = r.Value: r.Range("b1:c1").ClearContents
                    For Each sh In Worksheets
                        If Not sh.Name Like "Draft*" Then
                            team = sh.[a1]
                            Set c = sh.Cells.Find(player, , , 1)
                            If Not c Is Nothing Then
                                r(, 2).Value = team
                                r(, 3).Value = c.EntireRow.Range("a1").Value
                                Exit For
                            End If
                        End If
                    Next
                Next
            End If
        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)

Similar Threads

  1. Running the same macro across multiple VISIBLE sheets only
    By naltieri in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2021, 11:49 AM
  2. running a macro on multiple sheets
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-24-2015, 08:11 AM
  3. Question regarding running Macro across multiple sheets
    By whawk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-01-2014, 07:32 PM
  4. Running Same macro on Multiple sheets
    By shilpigupta79 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-01-2013, 03:29 AM
  5. Running Macro on multiple sheets
    By VKS in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-21-2013, 12:10 PM
  6. [SOLVED] Running Sub's in multiple other sheets
    By brhogan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2012, 02:58 AM
  7. Running macro in multiple sheets
    By shak1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-18-2009, 06:36 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