Results 1 to 3 of 3

Execute VBA codes across multiple sets of sheets via loop

Threaded View

  1. #1
    Registered User
    Join Date
    11-29-2016
    Location
    Miami
    MS-Off Ver
    13
    Posts
    1

    Execute VBA codes across multiple sets of sheets via loop

    I have multiple sets of sheets that interact with one another.

    For example:
    FS_Franch copy pastes values to FS_Franch_CPV
    ItemWide_Operator copy pastes values to ItemWide_Operator_CPV
    ItemWide copy pastes values to ItemWide_CPV

    To clean up my code, I would like to be able to create a loop such that it performs these operations to each pair of sheets. I know in Stata it is possible to write code such as:
    "foreach x of varlist FS_Franch ItemWide_Operator". However, I can't seem to find similar loop capabilities in VBA. Could someone please help enlighten me?

    Example code across a pair of sheets:

    Note: The cells will always remain the same across all pairs of sheets. The only thing that will be different is the name of the sheets. THANKS


    Sheets("FS_Franch").Select
        Range("P5:AB269").Select
        Selection.Copy
        Sheets("FS_Franch_CPV").Select
        Range("A1:M265").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
        
    ' Sorts table
    
        ActiveWorkbook.Worksheets("FS_Franch_CPV").ListObjects("FS_Franch_CPV_Table").Sort. _
            SortFields.Clear
        ActiveWorkbook.Worksheets("FS_Franch_CPV").ListObjects("FS_Franch_CPV_Table").Sort. _
            SortFields.Add Key:=Range("FS_Franch_CPV_Table[[#All],[Percentile]]"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("FS_Franch_CPV").ListObjects("FS_Franch_CPV_Table").Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    Last edited by alansidman; 11-30-2016 at 11:18 AM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Loop through workbook applying two different actions to two sets of sheets
    By ksayet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2015, 06:03 PM
  2. [SOLVED] Loop through of sheets and execute calculations based on dynamic sheet references
    By surePac in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-10-2014, 09:19 AM
  3. Replies: 2
    Last Post: 05-09-2014, 02:30 PM
  4. [SOLVED] Loop codes through multiple sheets (not all sheets in workbook)
    By hcyeap in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-18-2014, 02:11 AM
  5. Replies: 0
    Last Post: 01-28-2013, 02:25 PM
  6. vlookup codes - multiple sheets
    By intothewild in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2012, 05:40 PM
  7. [SOLVED] Unprotect, Execute Code, Reapply Protection for Multiple Sheets
    By catnam in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-23-2011, 01:06 PM

Tags for this Thread

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