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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Could it be that
VBA Code:
Set Dest = ThisWorkbook.Sheets("Job Card with Time Analysis")
should be
Rich (BB code):
Set wsDest = ThisWorkbook.Sheets("Job Card with Time Analysis")
 
Upvote 0
I`ve done the alteration but still no luck. Sorry a bit thick of me?

VBA Code:
wsDest.Range("G2").PasteSpecial xlPasteValues

The code above is failing
 
Upvote 0
The code above is failing
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
- error message? (what is the error message?) It says xlpastes values =-4163 which I don`t understand
- pastes the right thing in the wrong place? (details?) Does not paste any data
- pastes the wrong thing in the right place? (details?) Same as above
- does nothing? Yes that is right
- If you have merged cells in either sheet involving cell G2, please give details of the merged cells. Both sheets are G2:H2 cells merged
 
Upvote 0
Please can someone help starting to get a bit desperate?
The code below will not copy & paste a merged cell from one Sheet to another Sheet
Merged cells are ("G2:H3") on both sheets

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 wsDest = ThisWorkbook.Sheets("Job Card with Time Analysis")
 
        With Worksheets(wsSource).Range("G2").MergeCells_
        .Copy
      
        End With
          
        With Worksheets(wsDest).Range("G2")
            .MergeCells
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .PasteSpecial xlPasteValues
          
            End With
    End If
End Sub
 
Last edited:
Upvote 0
Both sheets are G2:H2 cells merged

Merged cells are ("G2:H3") on both sheets
Please be very careful with your descriptions as all we have to go on is what you tell us so when we see contradictions like the above, it can get confusing. ;)

Never-the-less assuming both sheets have the same cells merged, try this

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 wsDest = ThisWorkbook.Sheets("Job Card with Time Analysis")
 
  wsSource.Range("G2").MergeArea.Copy
  wsDest.Range("G2").MergeArea.PasteSpecial xlPasteValues
       
End If
 
Upvote 0
Hi sorry, me again this below is copying A13 down but does not seem to work.
Please help

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 wsDest = ThisWorkbook.Sheets("Job Card with Time Analysis")

 
[U]    wsSource.Range("A13" & Rows.Count).End(xlDown).Copy
   wsDest.Range("A13" & Rows.Count).End(xlDown).PasteSpecial xlPasteValues[/U]
 
    wsSource.Range("G2").MergeArea.Copy
  wsDest.Range("G2").MergeArea.PasteSpecial xlPasteValues

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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