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.
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!
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!