• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Consolidation of Multiple Sheet into one

Shabbo

Member
Dear Sir,

I have attached excel file which has got 39 sheets into same format and I want to consolidate into one sheet.

please advice.
 

Attachments

  • Copy of Ledger-1.xls
    305.5 KB · Views: 6
Code:
Sub consolidator()

Dim ws As Worksheet
Dim Curr, Consol, FstRow, LstRow As String
Dim finder

ActiveWorkbook.Worksheets.Add After:=Worksheets(Worksheets.Count)

ActiveSheet.Name = "Consolidated"

Consol = ActiveSheet.Name

Range("A1").Value = "Date"
Range("B1").Value = "No."
Range("C1").Value = "Particulars"
Range("D1").Value = "Debit"
Range("E1").Value = "Credit"
Range("F1").Value = "Balance"

For Each ws In ActiveWorkbook.Worksheets

    If ws.Name Like "Page*" Then
   
        ws.Select
        Curr = ws.Name
       
        On Error Resume Next
        finder = Cells.Find(What:="Total", LookIn:=xlFormulas, LookAt:=xlWhole)
       
        If IsEmpty(finder) Then
            LstRow = Range("A" & Cells(Rows.Count, "A").End(xlUp).Row).Row
        Else
            LstRow = finder - 1
        End If
       
        Cells.Find(What:="Particulars", LookIn:=xlFormulas, LookAt:=xlWhole).Activate
        FstRow = ActiveCell.Row + 1
       
        Range("A" & FstRow & ":G" & LstRow).Copy
        Worksheets(Consol).Select
        Range("A" & Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        Worksheets(Curr).Select
       
    Else
    End If
   
Next

Worksheets(Consol).Select
Range("A1").Select

MsgBox "Macro completed", vbInformation, ""

End Sub
 
Code:
Sub consolidator()

Dim ws As Worksheet
Dim Curr, Consol, FstRow, LstRow As String
Dim finder

ActiveWorkbook.Worksheets.Add After:=Worksheets(Worksheets.Count)

ActiveSheet.Name = "Consolidated"

Consol = ActiveSheet.Name

Range("A1").Value = "Date"
Range("B1").Value = "No."
Range("C1").Value = "Particulars"
Range("D1").Value = "Debit"
Range("E1").Value = "Credit"
Range("F1").Value = "Balance"

For Each ws In ActiveWorkbook.Worksheets

    If ws.Name Like "Page*" Then
  
        ws.Select
        Curr = ws.Name
      
        On Error Resume Next
        finder = Cells.Find(What:="Total", LookIn:=xlFormulas, LookAt:=xlWhole)
      
        If IsEmpty(finder) Then
            LstRow = Range("A" & Cells(Rows.Count, "A").End(xlUp).Row).Row
        Else
            LstRow = finder - 1
        End If
      
        Cells.Find(What:="Particulars", LookIn:=xlFormulas, LookAt:=xlWhole).Activate
        FstRow = ActiveCell.Row + 1
      
        Range("A" & FstRow & ":G" & LstRow).Copy
        Worksheets(Consol).Select
        Range("A" & Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        Worksheets(Curr).Select
      
    Else
    End If
  
Next

Worksheets(Consol).Select
Range("A1").Select

MsgBox "Macro completed", vbInformation, ""

End Sub
Dear SIr,

I got an error after pasting this code.

Please refer attached sheet.
 

Attachments

  • Copy of Ledger-1-1.xlsm
    176 KB · Views: 4
Macro will error if "Consolidated" sheet is already in file. So you will need to delete that sheet before you run the macro. I've rechecked my code & you need to replace this bit

Code:
        On Error Resume Next
        finder = Cells.Find(What:="Total", LookIn:=xlFormulas, LookAt:=xlWhole)

with this bit

Code:
        On Error Resume Next
        finder = Cells.Find(What:="Total", LookIn:=xlFormulas, LookAt:=xlWhole).Row

for some reason the ".Row" part at the end was missing
 
Back
Top