+ Reply to Thread
Results 1 to 5 of 5

Work Sheet consolidation Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    08-04-2008
    Location
    South Carolina
    Posts
    13

    Work Sheet consolidation Macro

    Greetings,

    I am working on a Macro that will consolidate 3 specific work sheets in my work book. I have it were it will consolidate all sheets but cannot get it to do just the 3 specific work sheets alone. Below is the Macro. I would like to only consolidate Sheets "Data1","Data2" and "Data3" into Sheet "Total"




    Sub TotalSheets()

    Dim cs As Worksheet, ws As Worksheet, LR As Long, NR As Long
    Application.ScreenUpdating = False

    If Not SheetExists("Total") Then _
    Worksheets.Add(Before:=Sheets(1)).Name = "Total"

    Set cs = Sheets("Total")
    cs.Cells.Clear
    Sheets(2).Rows(1).Copy cs.Range("A1")

    NR = 2

    For Each ws In Worksheets
    If ws.Name <> "Total" Then
    ws.Activate
    LR = Range("A1").SpecialCells(xlCellTypeLastCell).Row
    Range("A2:AA" & LR).Copy
    cs.Range("A" & NR).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    NR = cs.Range("A" & Rows.Count).End(xlUp).Row + 1
    End If
    Next ws

    cs.Activate
    Columns("A:AA").AutoFit
    Range("A1").Select
    Application.ScreenUpdating = True
    End Sub


    Thanks for any help
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Work Sheet consolidation Macro

    Try the Consolidate function under Data Tools

  3. #3
    Registered User
    Join Date
    08-04-2008
    Location
    South Carolina
    Posts
    13

    Re: Work Sheet consolidation Macro

    I tried using the Consolidate function. The data on the 3 sheets will vary month to month and I was unable to get it to bring the information correctly.

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Work Sheet consolidation Macro

    as an option
    Sub TotalSheets()
    Dim wsh, wshList: Application.ScreenUpdating = False
    If Not SheetExists("Total") Then Worksheets.Add(Before:=Sheets(1)).Name = "Total"
    wshList = Array("Data1", "Data2", "Data3")
    With Sheets("Total")
        .UsedRange.Clear
        Sheets(wshList(0)).Rows(1).Copy .Cells(1, 1)
        For Each wsh In wshList
            Sheets(wsh).Range("A1").CurrentRegion.Offset(1).Copy .Cells(Rows.Count, 1).End(xlUp).Offset(1)
        Next wsh
        .Activate: Columns("A:G").AutoFit: Range("A1").Select
    End With
    Application.CutCopyMode = False: Application.ScreenUpdating = True
    End Sub

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Work Sheet consolidation Macro

    Just referring back to your original macro, this line:
        For Each ws In Worksheets

    ...could be made to specify the sheets by:
        For Each ws In Worksheets(Array("Data1","Data2","Data3"))
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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