Merging cells from one Worksheet to another

Keojey

New Member
Joined
Sep 19, 2018
Messages
35
Office Version
  1. 365
Hello,

I have two worksheets where data from one is being copied over to the other. The issue I'm having has to do with trying to merge cells on the worksheet that has the data pasted to it.

To get a layout of what the Workbooks look like, I'll give a quick breakdown (I can't download XL2BB on this computer, sorry):
One Workbook is called Copy. Another is called Paste. Both only have one Worksheet named 'Sheet1'.
Copy's range 'A1' is some random number, let's say '6'. There is a button that holds the below code in it called 'Import'.
Copy's range of 'E3' to 'E5' is as follows:
[E3] - (The filepath to Paste.xlsx)
[E4] - Paste.xlsx
[E5] - Copy.xlsm
Paste only has 5 entries in it going from 'A1' to 'A5' with numbers '1' to '5' in them respectively.

VBA Code:
Sub CopyData()

Dim wbCopy As String, wbDest As String
Dim wsCopy As Worksheet, wsDest As Worksheet
Dim DestLastColumn As Long
 
  wbCopy = Sheets("Sheet1").Range("E5").Value
  wbDest = Sheets("Sheet1").Range("E4").Value
 
  Workbooks.Open Sheets("Sheet1").Range("E3")
 
  Set wsCopy = Workbooks(wbCopy).Worksheets("Sheet1")
  Set wsDest = Workbooks(wbDest).Worksheets("Sheet1")
       
  DestLastColumn = wsDest.Cells(1, Columns.Count).End(xlToLeft).Column
 
 wsDest.Range(Cells(1, DestLastColumn + 1), Cells(1, DestLastColumn + 3)).Merge '<---- The issue is happening here

 wsDest.Cells(1, DestLastColumn + 1) = wsCopy.Range("A1")

End Sub

All I'm trying to do is get this code to do is have the three cells to the right of Paste's last entry of '5' to merge and then add Copy's 'A1' entry of '6' into it. Unfortunately, it seems to keep hiccupping and giving me a '400' error when trying to merge.. and I can't seem to understand why!

Any sort of assistance is always appreciated!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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