Combining worksheets into summary with source worksheet

odonnke19

New Member
Joined
Oct 17, 2007
Messages
8
Morning, I tried the combine VBA below worked perfectly however it did not list the name of the worksheet ie. 18-01-01.xls as I thought it would. Any advice? I have over 104 tab/worksheets
Sub Combine()


Dim J As Integer


On Error Resume Next


Sheets(1).Select


Worksheets.Add


Sheets(1).Name = "Combined"


Sheets(2).Activate


Range("A1").EntireRow.Select


Selection.Copy Destination:=Sheets(1).Range("A1")


For J = 2 To Sheets.Count


Sheets(J).Activate


Range("A1").Select


Selection.CurrentRegion.Select


Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select


Selection.Copy Destination:=Sheets(1).Range("A1048575").End(xlUp)(2)


Next


End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Check if the following is useful to put the name of the sheet in column A

VBA Code:
Sub Combine()
  Dim J As Integer, lr As Long, lr2 As Long
  Sheets(1).Select
  Worksheets.Add
  Sheets(1).Name = "Combined"
  Sheets(2).Activate
  Range("A1", Cells(1, Columns.Count).End(1)).Copy Sheets(1).Range("B1")
  For J = 2 To Sheets.Count
    Sheets(J).Activate
    Range("A1").Select
    Selection.CurrentRegion.Select
    Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
    lr = Sheets(1).Range("A" & Rows.Count).End(3)(2).Row
    Selection.Copy Destination:=Sheets(1).Range("B" & lr)
    lr2 = Sheets(1).Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
    Sheets(1).Range("A" & lr & ":A" & lr2).Value = Sheets(J).Name
  Next
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top