Leorand
New Member
- Joined
- Nov 25, 2022
- Messages
- 18
- Office Version
- 365
- Platform
- Windows
So I got some problem on excel macro and the code like this :
Those code is used to copy some data in excel workbooks and paste to different workbooks. If there some old data in destination file, it will make an update bellow the old data. The code is work properly, but I want to change update location not in bellow old data but it will located in cells after the old data. Any advice?
VBA Code:
Sub Backup_button1()
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
'set variable for copy and destination sheets
Set wsCopy = Workbooks("Form Input SAP.xlsm").Worksheets("7-9")
Set wsDest = Workbooks("File Backup.xlsx").Worksheets("7-9")
'1. Find last used row in the copy range based on data in column
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "H").End(xlUp).Row
'2. Find first blank row in the destination range based on data in colom Offset property move down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "H").End(xlUp).Offset(1).Row
'3. Copy & Paste Data
wsCopy.Range("H4:N" & lCopyLastRow).Copy
wsDest.Range("B" & lDestLastRow).PasteSpecial Paste:=xlPasteValues
End Sub
Those code is used to copy some data in excel workbooks and paste to different workbooks. If there some old data in destination file, it will make an update bellow the old data. The code is work properly, but I want to change update location not in bellow old data but it will located in cells after the old data. Any advice?