jski21
Board Regular
- Joined
- Jan 2, 2019
- Messages
- 133
- Office Version
- 2016
- Platform
- Windows
Good day Mr. Excel Team,
Seeking to combine specific range of data from 17 different worksheets into a single table in a new worksheet. Header row is D7:O7 across all sheets, and range for extraction would be 100 rows down (might change as time goes on) from the header row.
Using the code below with some difficulty:
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" And ws.Name <> "Tables" And ws.Name <> "NDAForm" And ws.Name <> "BudgetAdj" And ws.Name <> "NDA Summary" _
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
Any assistance would be most appreciated. Thanks.
Seeking to combine specific range of data from 17 different worksheets into a single table in a new worksheet. Header row is D7:O7 across all sheets, and range for extraction would be 100 rows down (might change as time goes on) from the header row.
Using the code below with some difficulty:
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" And ws.Name <> "Tables" And ws.Name <> "NDAForm" And ws.Name <> "BudgetAdj" And ws.Name <> "NDA Summary" _
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
Any assistance would be most appreciated. Thanks.