Doomglazer
New Member
- Joined
- Mar 17, 2022
- Messages
- 11
- Office Version
- 365
- Platform
- Windows
Hello
I have an Excell with a new sheet with data for every working day. The sheets are labeled 0101,0201,0301,.... and this goes on till the end of the year.
I am using the following VBA code to consolidate all the data into a Master sheet. Now im looking for a way where i can say that i only want the data from 0104 to 3004 for example to be on the "Master" sheet
This is the code i use but it captures all the days. But i would like to provide a range where it will then run and provide me the data.
Sub Merge_Sheets()
Dim startRow, startCol, lastRow, lastCol As Long
Dim headers As Range
'Set Master sheet for consolidation
Set mtr = Worksheets("Master")
Set wb = ThisWorkbook
'Get Headers
Set headers = Application.InputBox("Select the Headers", Type:=8)
'Copy Headers into master
headers.Copy mtr.Range("A1")
startRow = headers.Row + 1
startCol = headers.Column
Debug.Print startRow, startCol
'loop through all sheets
For Each ws In wb.Worksheets
'except the master sheet from looping
If ws.Name <> "Master" Then
ws.Activate
lastRow = Cells(Rows.Count, startCol).End(xlUp).Row
lastCol = Cells(startRow, Columns.Count).End(xlToLeft).Column
'get data from each worksheet and copy it into Master sheet
Range(Cells(startRow, startCol), Cells(lastRow, lastCol)).Copy _
mtr.Range("A" & mtr.Cells(Rows.Count, 1).End(xlUp).Row + 1)
End If
Next ws
Worksheets("Master").Activate
End Sub
Thank you in advance
I have an Excell with a new sheet with data for every working day. The sheets are labeled 0101,0201,0301,.... and this goes on till the end of the year.
I am using the following VBA code to consolidate all the data into a Master sheet. Now im looking for a way where i can say that i only want the data from 0104 to 3004 for example to be on the "Master" sheet
This is the code i use but it captures all the days. But i would like to provide a range where it will then run and provide me the data.
Sub Merge_Sheets()
Dim startRow, startCol, lastRow, lastCol As Long
Dim headers As Range
'Set Master sheet for consolidation
Set mtr = Worksheets("Master")
Set wb = ThisWorkbook
'Get Headers
Set headers = Application.InputBox("Select the Headers", Type:=8)
'Copy Headers into master
headers.Copy mtr.Range("A1")
startRow = headers.Row + 1
startCol = headers.Column
Debug.Print startRow, startCol
'loop through all sheets
For Each ws In wb.Worksheets
'except the master sheet from looping
If ws.Name <> "Master" Then
ws.Activate
lastRow = Cells(Rows.Count, startCol).End(xlUp).Row
lastCol = Cells(startRow, Columns.Count).End(xlToLeft).Column
'get data from each worksheet and copy it into Master sheet
Range(Cells(startRow, startCol), Cells(lastRow, lastCol)).Copy _
mtr.Range("A" & mtr.Cells(Rows.Count, 1).End(xlUp).Row + 1)
End If
Next ws
Worksheets("Master").Activate
End Sub
Thank you in advance