Copy and paste

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Hi All

Can someone tell me why this code below is not working.
I think it copies ok but won't paste into merged cells.
It's copying from merged cells to merged cells in separate worksheets.

VBA Code:
If ListBox4 = "Add Data to Jobcard Analysis Sheet" Then
   
   Dim wsSource    As Worksheet
   Dim wsDest      As Worksheet
   
   Set wsSource = ThisWorkbook.Sheets("Job Card Master")
   Set Dest = ThisWorkbook.Sheets("Job Card with Time Analysis")
   
        wsSource.Range("G2").Copy
        wsDest.Range("G2").PasteSpecial xlPasteValues
        
       
    End If
End Sub
 
this below is copying A13 down but does not seem to work.
As before ...
That gives us nothing to go on. ;)

In what way is it failing?
- error message? (what is the error message?)
- pastes the right thing in the wrong place? (details?)
- pastes the wrong thing in the right place? (details?)
- does nothing?
- etc

If you have merged cells in either sheet involving cell G2, please give details of the merged cells.
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
As before ...
- error message? (what is the error message?) Error "Range of object worksheet failed" Error 1004
- pastes the right thing in the wrong place? (details?) Does not paste
- pastes the wrong thing in the right place? (details?) As above
- does nothing? Yes Correct
- etc This is the line not working see below
VBA Code:
VBA Code:
[U]    wsSource.Range("A13" & Rows.Count).End(xlDown).Copy
   wsDest.Range("A13" & Rows.Count).End(xlDown).PasteSpecial xlPasteValues[/U]
 
Upvote 0
Can you describe in words what you are trying to copy with this code?

VBA Code:
 wsSource.Range("A13" & Rows.Count).End(xlDown).Copy
 
Upvote 0
VBA Code:
Set Dest = ThisWorkbook.Sheets("Job Card with Time Analysis")

This presumably should be :
VBA Code:
Set wsDest = ThisWorkbook.Sheets("Job Card with Time Analysis")
 
Upvote 0
VBA Code:
Set Dest = ThisWorkbook.Sheets("Job Card with Time Analysis")

This presumably should be :
VBA Code:
Set wsDest = ThisWorkbook.Sheets("Job Card with Time Analysis")
Yes that`s correct
 
Upvote 0
Copy rows from A13 down to the bottom of the sheet
If you want to do that you need something much more like this

VBA Code:
With wsSource
  .Range("A13", .Range("A13").End(xlDown)).Copy
End With
wsDest.Range("A13").PasteSpecial xlPasteValues
 
Upvote 0
VBA Code:
Set Dest = ThisWorkbook.Sheets("Job Card with Time Analysis")

This presumably should be :
VBA Code:
Set wsDest = ThisWorkbook.Sheets("Job Card with Time Analysis")
.. as mentioned in post #2. ;)
 
Upvote 0
Still, no luck This line below goes yellow. Some cells to copy & paste are merged if that makes a difference?

VBA Code:
wsDest.Range("A13").PasteSpecial xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

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