Solved

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

Posted on 2011-03-21
9
249 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:KathrynT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 35183514
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

0
 

Author Comment

by:KathrynT
ID: 35183546
Hi Thomas,

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

Kathryn
0
 

Author Comment

by:KathrynT
ID: 35185032
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 35185058
oops

line 7 should be = False, not =f

Press F5 in Visual Basic editor to get out of the Can't execute in break mode.

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 = False '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
shtDone.Cells.EntireRow.AutoFit
Application.ScreenUpdating = True
End Sub

Open in new window

0
 

Author Comment

by:KathrynT
ID: 35185104
Thanks, Thomas.

I'll try again.

Kathryn
0
 

Author Comment

by:KathrynT
ID: 35185185
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
0
 
LVL 39

Assisted Solution

by:nutsch
nutsch earned 500 total points
ID: 35185207
Agreed, my initial  comment was:
#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?

Let me know if you want the code to handle this, or if you will handle it prior to running the code?

Thomas
0
 

Author Comment

by:KathrynT
ID: 35185273
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
0
 

Author Comment

by:KathrynT
ID: 35185488
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
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question