Modular spreadsheet to reduce re-work

ea123

New Member
Joined
Dec 13, 2008
Messages
21
Good day:

I have a spreadsheet with multiple tabs. On the same spreadsheet, I have a worksheet called "List". List has names of several tabs in column A. I am using the following code to copy various tabs, in a sequential order, as listed in Worksheet "List" to another worksheet called "Consolidate", all within the same spreadsheet.

I want to enhance this code, so I can:

1. Have multiple list tabs, lets say List1, List 2 and List3 and copies the tabs listed in those lists, in sequential order and pastes those in another Spreadsheet.
2. The other spreadsheet will create a tab each for List1, List2, List3. Each one of these tabs will be copied from the other spreadsheet as defined in List1, List2, List 3 etc...

The intent behind this is to minimize the maintenance on tabs that are listed in List1, List2, lIST3. Wherever those tabs change, I want to run this code and copy paste the new content and reduce the work of copying-pasting multiple times. Hope it makes sense!

Appreciate the help! Thanks.

Code:
Option Explicit
Sub Consolidate()

    'Dim i As Integer
    Dim w As Worksheet
    Dim rngMyCell As Range
    Dim lngLastRow As Long
    
    On Error Resume Next
        Sheets(1).Select
        Worksheets.Add ' add a worksheet for consolidation of other tabs
        Sheets(1).Name = "Consolidate"
        
        ' copy headings
        Sheets(2).Activate
        Range("A1").EntireRow.Select
        Selection.Copy Destination:=Sheets(1).Range("A1")
        
        'Works from cell A2 down column A from the 'List' tab.  Change to suit if necessary.
        lngLastRow = Sheets("List").Cells(Rows.Count, "A").End(xlUp).Row
        For Each rngMyCell In Sheets("List").Range("A2:A" & lngLastRow)
            For Each w In ActiveWorkbook.Sheets
                If w.Name <> "Consolidate" Then
                    If w.Name = CStr(rngMyCell) Then
                        Application.Goto Sheets(w.Name).[a1]
                        Selection.CurrentRegion.Select
                        ' Don't copy the headings
                        Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
                        Selection.Copy Destination:=Sheets("Consolidate"). _
                        Cells(Rows.Count, 1).End(xlUp)(2)
                    End If
                End If
            Next w
        Next rngMyCell
    On Error GoTo 0
    
End Sub

EDIT: Added Code tags - Moderator
 
Last edited by a moderator:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top