Update data from copy-paste in excel is located on bellow the old data. How can I change the location?

Leorand

New Member
Joined
Nov 25, 2022
Messages
18
Office Version
  1. 365
Platform
  1. Windows
So I got some problem on excel macro and the code like this :

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?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
From which row does your data start in destination file?
And will there be multiple updates to destination file or only one?
If multiple copying will occur then, some sample data will be needed.
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,219
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top