KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 453
- Office Version
- 2016
- Platform
- Windows
Hi
I have a challenge. I use this VBA code to gather data from multiple sheets.
The data I want to collect is in column K to column S and all the way down.
I would like to have them put into Sheets Bestilling and start at cell A9.
possible only to copy numbers and text so that the formulas do not come with.
All help will be appreciated.
Best Regartds
Klaus W
I have a challenge. I use this VBA code to gather data from multiple sheets.
The data I want to collect is in column K to column S and all the way down.
I would like to have them put into Sheets Bestilling and start at cell A9.
possible only to copy numbers and text so that the formulas do not come with.
All help will be appreciated.
Best Regartds
Klaus W
VBA Code:
Sub Rektangelafrundedehjørner1_Klik()
Dim startRow, startCol, lastRow, lastCol As Long
Dim headers As Range
'Set Master sheet for cosolidation
Set mtr = Worksheets("Master")
Set wb = ThisWorkbook
'Get Headers
Set headers = Range("k2")
Set headers = Application.Range("k2")
'InputBox("Select the Headers", Type:=8)
headers.Copy mtr.Range("k2")
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