Copy and Paste

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code and first part is all correct it does the copy and past from one sheet to another, but 2nd part of copy and paste is not working, there is no error and it is not even copying and pasting the data.

any suggestions.

VBA Code:
Sub CurrenttrackertoDB()
'''''''''''''''''''''''''''''''''''''''''''''''''''
'this is conver the current tracker to
'DB
'
''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
Dim iSourceLastRow As Long
Dim iTargetLastRow As Long


Set wsSource = Worksheets("Tracker - RawData")
Set wsTarget = Worksheets("DB - RawData")

iSourceLastRow = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
iTargetLastRow = wsTarget.Cells(wsTarget.Rows.Count, "A").End(xlUp).Offset(1).Row
'Copy data from the source and Paste in the destination
wsSource.Range("A7:AZ7" & iSourceLastRow).Copy wsTarget.Range("A" & iTargetLastRow) 'this 1st part is all correct

wsSource.Range("BK7" & iSourceLastRow).Copy wsTarget.Range("BA" & iTargetLastRow) 'this part of code is not working

End Sub
 
Last edited by a moderator:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
wsSource.Range("BK7" BK7 is a red flag here. Most probably it will be "BK" only.
 
Upvote 0
I doubt either of these two lines are doing what you think they are
VBA Code:
wsSource.Range("A7:AZ7" & iSourceLastRow).Copy wsTarget.Range("A" & iTargetLastRow) 'this 1st part is all correct

wsSource.Range("BK7" & iSourceLastRow).Copy wsTarget.Range("BA" & iTargetLastRow) 'this part of code is not working
If iSourceLastRow is 100 then you are copying A7:AZ700 to col A & then copying BK700 to col BA
 
Upvote 0
I doubt either of these two lines are doing what you think they are
VBA Code:
wsSource.Range("A7:AZ7" & iSourceLastRow).Copy wsTarget.Range("A" & iTargetLastRow) 'this 1st part is all correct

wsSource.Range("BK7" & iSourceLastRow).Copy wsTarget.Range("BA" & iTargetLastRow) 'this part of code is not working
If iSourceLastRow is 100 then you are copying A7:AZ700 to col A & then copying BK700 to col BA
thanks
below code worked for me for 2nd part, the 1st part the is no change.

VBA Code:
Dim iSourceLastRowBK As Long
Dim iTargetLastRowBK As Long
iSourceLastRowBK = wsSource.Cells(wsSource.Rows.Count, "BK").End(xlUp).Row
iTargetLastRowBK = wsTarget.Cells(wsTarget.Rows.Count, "BA").End(xlUp).Offset(1).Row

wsSource.Range("BK7:BK7" & iSourceLastRowBK).Copy wsTarget.Range("BA" & iTargetLastRowBK)
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0
thanks
below code worked for me for 2nd part, the 1st part the is no change.
Although you say it is now working I think you are missing the point and you are actually copying far more rows than you are intending to copy.
It just so happens that those rows are blank.

Add the code below under your BK7 copy line and check if what you see makes sense. If it does well and good but I think it is unlikely.

VBA Code:
MsgBox _
        "1st Range Being Copied is: " & wsSource.Range("A7:AZ7" & iSourceLastRow).Address & Chr(10) & _
        "1st Range Last Row Copied: " & wsSource.Range("AZ7" & iSourceLastRow).Row & Chr(10) & _
        "2nd Range Being Copied is: " & wsSource.Range("BK7:BK7" & iSourceLastRowBK).Address & Chr(10) & _
        "2nd Range Last Row Copied: " & wsSource.Range("AZ7" & iSourceLastRowBK).Row
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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