I posted this before but modified it since my original ask had too many steps.
I have a sourcedata wb SourceData FY24 and a destination wb Destination FY24.
Within wb Destination FY24, ws Mission Control, and cell "B3" there is a name listed which I want to use to filter the range to copy. Steps wanted:
1. Clear all data from cells "AF2 to BW10" in ws Mission Control of wb Destination FY24. Code must be dynamic since table size can change.
2. Copy only rows from wb SourceData FY24 and ws SourceData that match value in "B3" of Destination FY24.
3. Paste copied data into Destination FY24 starting in cell "AF2".
My current code does not work fully and need feedback:
Sub Insert_SC()
Application.ScreenUpdating = False
Dim wbSource As Workbook
Dim wbDest As Workbook
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim SourceRng As Range
Dim NameRng As Range
Dim DestRng As Range
Dim DestLastRow As Long
Workbooks.Open ("C:\Users\kerah\SourceData FY24.xlsx")
Workbooks.Open ("C:\Users\kerah\Destination FY24.xlsx")
Set wbSource = Workbooks("SourceData FY24.xlsx")
Set wbDest = Workbooks("Destination FY24.xlsx")
Set wsSource = wbSource.Worksheets("SourceData")
Set wsDest = wbDest.Worksheets("Mission Control")
Set SourceRng = wsSource.Range("E1").CurrentRegion
Set NameRng = wsDest.Range("B3").CurrentRegion
Set DestRng = wsDest.Range("AF1:BW1")
DestLastRow = wsDest.Cells(wsDest.Rows.Count, "AF").End(xlUp).Offset(1).Row
wsDest.Range("AF2:BW" & DestLastRow).ClearContents
SourceRng.AdvancedFilter xlFilterCopy, NameRng, DestRng
wbDest.Save
wbDest.Close
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Bookmarks