Forum Discussion
ccate
Feb 04, 2021Copper Contributor
How combined data from multiple sheets to one sheet.
I have a document with 7 sheets with data. Each have the same 4 column headers and each vary in the number of rows from as many as 2500 on one and only 5 on another. What I want to do it have al...
- Feb 04, 2021
Try this macro:
Sub CombineSheets() Dim wshS As Worksheet Dim wshT As Worksheet Dim i As Long Dim t As Long Dim rng As Range Application.ScreenUpdating = False Set wshT = Worksheets.Add(Before:=Worksheets(1)) t = 1 For i = 2 To Worksheets.Count Set wshS = Worksheets(i) Set rng = wshS.UsedRange If i > 2 Then Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1) End If rng.Copy Destination:=wshT.Range("A" & t) t = t + rng.Rows.Count Next i Application.ScreenUpdating = True End Sub
HansVogelaar
Feb 04, 2021MVP
Try this macro:
Sub CombineSheets()
Dim wshS As Worksheet
Dim wshT As Worksheet
Dim i As Long
Dim t As Long
Dim rng As Range
Application.ScreenUpdating = False
Set wshT = Worksheets.Add(Before:=Worksheets(1))
t = 1
For i = 2 To Worksheets.Count
Set wshS = Worksheets(i)
Set rng = wshS.UsedRange
If i > 2 Then
Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)
End If
rng.Copy Destination:=wshT.Range("A" & t)
t = t + rng.Rows.Count
Next i
Application.ScreenUpdating = True
End Sub- ccateFeb 04, 2021Copper Contributor
This worked great. I do get an error message but I just select "Ok" and it appears to have done what I wanted it to do.
This is awesome, thanks so much!
- HansVogelaarFeb 04, 2021MVP
What did the error message say?
- ccateFeb 04, 2021Copper Contributor