Solved

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

Posted on 2011-03-21
9
248 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
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.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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