Hi, I have a working script from here which works to a point after Ive saved a temp workbook exported from accountancy system to excel., giving it a filename to ref.
So need to change script slightly.
My workbook where I get the source data from changes as its always a differently named temp file e.g. tmp4313.xlsx
Need to change this "sas 30.09.xlsx" in my script to compensate for the temp file if possible save me saving this temp file each time.
This will be the only temp file open at the time of running the script.
Any help much appreciated.
So need to change script slightly.
My workbook where I get the source data from changes as its always a differently named temp file e.g. tmp4313.xlsx
Need to change this "sas 30.09.xlsx" in my script to compensate for the temp file if possible save me saving this temp file each time.
This will be the only temp file open at the time of running the script.
Any help much appreciated.
VBA Code:
ption Explicit
Sub Copy_Paste_Below_Last_Cell()
'Find the last used row in both sheets and copy and paste data below existing data.
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
'Set variables for copy and destination sheets
Set wsCopy = Workbooks("sas 30.09.xlsx").Worksheets("SAS Fix")
Set wsDest = Workbooks("Gareth's SAS Master.xlsm").Worksheets("2017 onwards")
'1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
'2. Find first blank row in the destination range based on data in column A
'Offset property moves down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
'3. Copy & Paste Data
wsCopy.Range("A2:O" & lCopyLastRow).Copy _
wsDest.Range("A" & lDestLastRow)
'Optional - Select the destination sheet
wsDest.Activate
End Sub