PDA

View Full Version : Is there a way to Paste text into a Merged Excel Cell, from an outside file?



JimC
12-04-2007, 08:55 AM
When Pasting text from another source (not excel) I get a Microsoft Excel Warning "Data on the clipboard is not the same size and shape as the selected area. Do you want to paste the data anyway?"

Click ok
Another Excel warning comes up, "Cannot change part of a merged cell."

Is there a way to force the cell to accept the pasted text?

Maybe an automatic macro that unmerges the cell, pastes the text, then remerges the cell again? This only seems to happen when copying from an a non-excel file. Any advise would be appreciated...
Thanks....

mvidas
12-07-2007, 07:43 AM
Hi Jim,

You could use a data object to retrieve the text from the clipboard, then put that as the .value of the merged cell. The following macro will put the clipboard contents into the active cell (merged or not):Sub InsertClipboardDataIntoMergedCell()
Dim DataObj As MSForms.DataObject
Set DataObj = New MSForms.DataObject
DataObj.GetFromClipboard
ActiveCell.Value = DataObj.GetText
Set DataObj = Nothing
End Sub

JimC
12-10-2007, 06:11 AM
Hi Jim,

You could use a data object to retrieve the text from the clipboard, then put that as the .value of the merged cell. The following macro will put the clipboard contents into the active cell (merged or not):Sub InsertClipboardDataIntoMergedCell()
Dim DataObj As MSForms.DataObject
Set DataObj = New MSForms.DataObject
DataObj.GetFromClipboard
ActiveCell.Value = DataObj.GetText
Set DataObj = Nothing
End Sub

JimC
12-10-2007, 06:12 AM
Problem Solved! Thanks very much for the quick response -
Jim C

mvidas
12-10-2007, 07:53 AM
Glad to help! Sorry it took 3 days for someone to respond :)