I've got a basic understanding of VBA and usually just google my way out when i'm stuck, but this time I have looked around and can't seem to find a solution for my problem.
I've got a 'source' workbook which contains multiple sheets. Each month the workbook name changes and so do the worksheet names. I'm trying to consolidate the data from each of those worksheets into a 'Summary' workbook. there is some usless cells, so i only require some specific data. The number of rows in the 'source' worksheets varies, but the columns stay the same. The source worksheets have a single date at the top of sheet, which i want to insert a column in A:A and then filldown the date for each row entry.
I've tried both the 'For each ws in worksheets' and the 'for i = 1 to sheet count' methods and what ends up happening is that it copies data from only 1 sheet, but it repeats it multiple times, my guess is for how many sheets are in the workbook.
Really appreciate any help you can give. Thanks in advance. I don't know too much about coding so would appreciate any tips.
Private Sub CopyfromSheet()
Dim ws As Worksheet
Workbooks("source.xls").Activate
For each ws in Workbooks("source").Worksheets
'add date column and copy date
Columns(1).Insert
Range("D2").Copy
Range("A3").Select
Selection.PasteSpecial xlPasteValues
'fill down date to the last row
Range("B3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
'copy source data to next free row in Summary sheet
Range("A4:E4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ThisWorkbook.Activate
Worksheets("Data").Range("A2").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Workbooks("source").Activate
next ws
End Sub