MasterExcel
New Member
- Joined
- May 24, 2021
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Hi Everyone,
I'm struggling to modify the code that I have to copy an extra dynamic range to the master sheet.
I have a master task sheet with code to copy a dynamic range (A2:E) from all sheets with the word "Data" at the end of the sheet name.
I'd also like to copy the data from the range G2:G from the same sheets but I can't seem to get the syntax right...
Any help would be gratefully received!
My code is below:
I'm struggling to modify the code that I have to copy an extra dynamic range to the master sheet.
I have a master task sheet with code to copy a dynamic range (A2:E) from all sheets with the word "Data" at the end of the sheet name.
I'd also like to copy the data from the range G2:G from the same sheets but I can't seem to get the syntax right...
Any help would be gratefully received!
My code is below:
VBA Code:
Sub RetrieveData()
Dim ws As Worksheet
With Sheets("Master Tasks")
If .Range("A2") <> "" Then .Range("A2:E" & .Range("A" & Rows.Count).End(xlUp).Row).ClearContents
For Each ws In Worksheets
If ws.Name Like "*Data" Then
ws.Range("A2:E" & ws.Range("A" & Rows.Count).End(xlUp).Row).Copy .Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next ws
End With
End Sub