Forum Discussion
alex_n
Mar 30, 2022Brass Contributor
Excel VBA code to copy a range of data from certain tabs into summary tab
Hello everyone! I have several workbooks (i prepared two WB1 and WB2 for this example but it is over 30 workbooks) that have common tabs like Summary tab and other tabs with tab names that start ...
- Mar 31, 2022
Try this version:
Sub Summarize() Dim ws As Worksheet Dim wt As Worksheet Dim rngs As Range Dim rngt As Range Application.ScreenUpdating = False Set wt = Worksheets("Summary") wt.UsedRange.Offset(1).Clear For Each ws In Worksheets If ws.Name Like "WLD -*" Then Set rngs = ws.Range("F2:J147") rngs.AutoFilter Field:=1, Criteria1:="<>" rngs.Offset(1).Copy Set rngt = wt.Range("A" & Rows.Count).End(xlUp).Offset(1) rngt.PasteSpecial Paste:=xlPasteValues rngs.AutoFilter End If Next ws Application.CutCopyMode = False wt.UsedRange.EntireColumn.AutoFit Application.ScreenUpdating = True End Sub
alex_n
Mar 31, 2022Brass Contributor
Hans, thank you for the help. The code works great! Would you mind modifying your code to accommodate the following: 1) I want only the data from WLDs in range F3:J147 to be copied over to Summary and 2) paste as values only, not the formatting.
Thanks again!
AN
Thanks again!
AN
HansVogelaar
Mar 31, 2022MVP
Try this version:
Sub Summarize()
Dim ws As Worksheet
Dim wt As Worksheet
Dim rngs As Range
Dim rngt As Range
Application.ScreenUpdating = False
Set wt = Worksheets("Summary")
wt.UsedRange.Offset(1).Clear
For Each ws In Worksheets
If ws.Name Like "WLD -*" Then
Set rngs = ws.Range("F2:J147")
rngs.AutoFilter Field:=1, Criteria1:="<>"
rngs.Offset(1).Copy
Set rngt = wt.Range("A" & Rows.Count).End(xlUp).Offset(1)
rngt.PasteSpecial Paste:=xlPasteValues
rngs.AutoFilter
End If
Next ws
Application.CutCopyMode = False
wt.UsedRange.EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub