VBA Pastespecial merged cells

twifosp

Board Regular
Joined
Nov 6, 2009
Messages
56
I have some code that looks like:

Code:
Workbooks(wb1).Activate
Range("b35:d36").Copy
Workbooks(wb2).Activate
ActiveCell.Resize(2, 1).Select
'ActiveCell.PasteSpecial (xlPasteValues)

It switches to workbook1 and selects the range. The range looks like :

b c d
<TABLE style="WIDTH: 163pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=217 border=0 x:str><COLGROUP><COL style="WIDTH: 44pt; mso-width-source: userset; mso-width-alt: 2157" width=59><COL style="WIDTH: 58pt; mso-width-source: userset; mso-width-alt: 2816" width=77><COL style="WIDTH: 61pt; mso-width-source: userset; mso-width-alt: 2962" width=81><TBODY><TR style="HEIGHT: 25.5pt" height=34><TD class=xl25 style="BORDER-RIGHT: #ebe9ed; BORDER-TOP: #ebe9ed; BORDER-LEFT: windowtext 1pt solid; WIDTH: 163pt; BORDER-BOTTOM: #ebe9ed; HEIGHT: 25.5pt; BACKGROUND-COLOR: transparent" width=217 colSpan=3 height=34 x:num="-0.27800000000000002">-0.3</TD></TR><TR style="HEIGHT: 25.5pt" height=34><TD class=xl24 style="BORDER-RIGHT: #ebe9ed; BORDER-TOP: #ebe9ed; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: #ebe9ed; HEIGHT: 25.5pt; BACKGROUND-COLOR: transparent" colSpan=3 height=34> 1</TD></TR></TBODY></TABLE>

So its b c and d 3 columns merged into 1 cell.

Then it switches to workbook2 and attempts to paste them into 2 rows that are also 3 columns merged into 1 cell.

When I execute the code above I get an error that the operation requires the merged cells to be identical size. But they are. If I comment out the last line and manually press control V, it works fine.

Is this an excel vba problem or mine?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Works for me:

I didn't do any significant changes. I used b5:d6, merged them on both workbooks, selected b5:d6 and it seems to do just fine.

my code in standard module.
Code:
Sub test()
Workbooks("book1").Activate
Range("b5:d6").Copy
Workbooks("book2").Activate
ActiveCell.Resize(2, 1).Select
ActiveCell.PasteSpecial (xlPasteValues)
End Sub

You do need to make sure the last line is not a comment
 
Upvote 0

Forum statistics

Threads
1,214,657
Messages
6,120,769
Members
448,991
Latest member
Hanakoro

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