Link to home
Start Free TrialLog in
Avatar of KathrynT
KathrynTFlag for United States of America

asked on

Correct consolidated data from mulltiple worksheets into a worksheet of a same workbook.

Hello Experts,

Thomas and Dave from EE were so kind to help me consolidate multiple worksheets.  I'm very happy with the results.  But when I run the macro  I experience some errors as following:
Please see my file attached.

1/  Please note I highlighted in yellow the names in column B.  These names are represent the tabs name for each worksheet in the workbook.  I don't want these names here.

2/  Please note the data roll up from SWIFT worksheet are missing.  It begins with 2 blank SWIFT row, and end with #12 data.  Missing #13 and #14.

3/  The data also are missing from PEG worksheet.  It begins with 2 blank PEG rows like SWIFT above, and end with #4.  Missing #5 and #6 data.

4/  It would be nice if the header can roll over too.

Can you please help.

Thanks.

Kathryn

Test-3.xls
Avatar of nutsch
nutsch
Flag of United States of America image

Hi Kathryn,

Here is an update that will fix #1 and #4 for you. #2 and 3 come because you have two empty lines in row 151 and 152 of both these tabs? Should the code take care of that too?

Thomas




Sub consolidateSheets()
Dim shtDone As Worksheet, lstRow As Long
Dim wksht As Worksheet, firstSheet As Boolean

Const bolTitles As Boolean = True 'True if sheets have titles, false if they don't
Const strSummary As String = "All" ' update to the name of the consolidated destination
Const bolTab As Boolean = f 'get data from tab name ? True / False
Const strTabTitle As String = "Type" 'title of column from tab name if bolTab=true
Dim lgTabCol As Long

'Call TurnOffAllUpdates(True)

Set shtDone = Sheets.Add

On Error Resume Next
shtDone.Name = strSummary

If Err.Number <> 0 Then
    ActiveWorkbook.Sheets(strSummary).Delete
    shtDone.Name = strSummary
    Err.Clear
End If
Application.ScreenUpdating = False
firstSheet = True

For Each wksht In ActiveWorkbook.Sheets
    
    If wksht.Name = strSummary Or Not wksht.Visible = xlSheetVisible Then GoTo nxtSht
    
    lstRow = shtDone.Range("A" & Rows.Count).End(xlUp).Row
    
    wksht.[a152].CurrentRegion.Resize(wksht.Cells(Rows.Count, 1).End(xlUp).Row - 150).Copy _
            shtDone.Cells(lstRow + 1, 1)

    If bolTitles = True And firstSheet = False Then
        Rows(lstRow + 1).Delete
        Rows(lstRow + 1).Delete 'MERGED TITLE ROW
    Else
        If bolTab = True And firstSheet = True Then
            lgTabCol = shtDone.UsedRange.Columns.Count + 1
            shtDone.Cells(2, lgTabCol) = strTabTitle
            lstRow = lstRow + 1
        End If
    End If
    
    If bolTab = True Then
        shtDone.Cells(lstRow + 1, lgTabCol) = wksht.Name
    End If
        
    firstSheet = False

nxtSht:
Next

If bolTab = True Then
    Intersect(ActiveSheet.UsedRange, Columns(lgTabCol)).Offset(1, 0).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    Columns(lgTabCol).Copy
    ActiveSheet.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
End If

shtDone.Cells.EntireColumn.AutoFit

Application.ScreenUpdating = True
End Sub

Open in new window

Avatar of KathrynT

ASKER

Hi Thomas,

Thanks for your quick response.  I'm going to try out now.

Kathryn
Hi Thomas,

I got an error message "can't execute code in brake mode".

Can you please review my attached workbook.

Thanks

Kathryn
Test-4.xls
ASKER CERTIFIED SOLUTION
Avatar of nutsch
nutsch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Thomas.

I'll try again.

Kathryn
Hi Thomas,

I ran the test.  It's great!!

You have solved the mystery of my  question # 1 and # 4 above.  But line #34 supposed to roll over the data from tab "SWIFT" and line # 48 to roll over the data from tab "PEG".  Both of these rows are left blank.

In summary,  the data roll up from 'SWIFT" and "PEG" tabs are not correct.

Can you please help.

Thanks again, Thomas.

Kathryn
Test-4.xls
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oop!  It's my mistake.  Let me take care of these lines and rerun your code.

I'll let you know soon.

Thanks again.

Kathryn
Hi Thomas,

This is great !!  It works very well.

My nanager ask me if we update the rolup worksheet which we will do all the works to it, can the others worksheet update automatically.

Thanks.

Kathryn
Test-4.xls