• 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.

Wroksheet consolidation

Dear All,

I am trying to consolidate worksheets "Forms Analysis,G_drive,Scroll_Word,Scroll_PDF and System Issue" into "Summary" worksheet in the attached file.

But the challenge is I need to get few common cell details from Home sheet like "Employee Name, ID, TL, and area belong to (Column D3 to D6)" to summary Sheet while consolidating details from rest other sheet details.

I have updated the sample result in Summary sheet manually.

Kindly help me to get solution for this problem. Thanks in advance.

Regards,
Raj
 

Attachments

  • Consolidate worksheet data.xlsm
    52.4 KB · Views: 10
Hi Luke,

With the following code I am able to consolidate, but still I am not able to fetch the data from home sheet like "Employee Name, ID, TL, and area belong to which are in (Column D3 to D6)" to summary Sheet. Also the following code considering the home sheet while consolidating.

Kindly help me to exclude the home sheet while consolidating and I am looking to capture only (Column D3 to D6) from Home sheet.

Thank you.

Code:
Sub ConsolidateWorksheets()
  Dim wrk As Workbook 'Workbook object - Always good to work with object variables
  Dim sht As Worksheet 'Object for handling worksheets in loop
  Dim trg As Worksheet 'Master Worksheet
  Dim rng As Range 'Range object
  Dim colCount As Integer 'Column count in tables in the worksheets
 
  Set wrk = ActiveWorkbook 'Working in active workbook
 
  'Delete the sheet "Summary-Sheet" if it exist
  Application.DisplayAlerts = False
  On Error Resume Next
  ThisWorkbook.Worksheets("Summary").Delete
  On Error GoTo 0
  Application.DisplayAlerts = True
  'Add a worksheet with the name "Summary-Sheet"
  Set wrk = ThisWorkbook
  Set trg = wrk.Worksheets.Add(After:=wrk.Worksheets(wrk.Worksheets.Count))
  trg.Name = "Summary"
 
 
  Application.ScreenUpdating = False
 
  'Add new worksheet as the last worksheet
 
  trg.Range("A1:J1").Value = Array("S.No", "Employee ID", "Employee Name", "Area Belong to", "TL", "Issue Type", "Issue Start Time", "Issue End Time", "Loss Time", "Issue Description")
 
  Set sht = wrk.Worksheets(1)
  colCount = sht.Cells(1, 255).End(xlToLeft).Column
  'Now retrieve headers, no copy&paste needed
  With trg.Cells(1, 1).Resize(1, colCount)
  Value = sht.Cells(1, 1).Resize(1, colCount).Value
  'Set font as bold
  .Font.Bold = True
  End With
 
  'We can start loop
  For Each sht In wrk.Worksheets
  'If worksheet in loop is the last one, stop execution (it is Master worksheet)
  If sht.Index = wrk.Worksheets.Count Then
  Exit For
  End If
  'Data range in worksheet - starts from second row as first rows are the header rows in all worksheets
 
  Set rng = sht.Range(sht.Cells(3, 6), sht.Cells(65536, 2).End(xlUp).Resize(, colCount))
  'Put data into the Master worksheet
  trg.Cells(65536, 6).End(xlUp).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
  Next sht
  'Fit the columns in Master worksheet
  trg.Columns.AutoFit
 
 
  'Screen updating should be activated
  Application.ScreenUpdating = True
End Sub
 
Apologies, but I am slightly confused. Are you wanting to exclude the home sheet (what is the sheet name?), or include the home sheet? If the latter, are we only including a small portion?

To exclude the home sheet, we would add a line in the For loop like:
If sht.Name <> "Home Sheet" Then

As for the range D3:D6, you should look at line 45 of the code. That is what defines the range to be copied. Again, I'm not sure which sheet this is supposed to be coming from.
 
Back
Top