xlPasteValues not working, need to match destination format, but getting error

ajdinspector

New Member
Joined
Nov 5, 2018
Messages
8
Hi! So i have a data set that is exported by a database, so can't change it's format. I have a script to copy and paste it into my sheet and it works fine:
Code:
'set the range reference variables
Set Bk = Sheet3.Range("C5") 'file path of book to import from
Set Sh = Sheet3.Range("F5") 'sheet to import
Set St = Sheet3.Range("G5") 'starting cell reference
Set Fn = Sheet3.Range("H5") 'finishing cell reference
Set Tb = Sheet3.Range("I5") 'sheet in this workbook to send it to
'set the destination
Set addme = Worksheets(Tb.Value).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
'open the workbook
Set wb = Workbooks.Open(Bk)
'set the copy range
Set CopyData = Worksheets(Sh.Value).Range(St & ":" & Fn)
'copy and paste the data
CopyData.Copy
addme.PasteSpecial xlPasteValues
One of my formulas doesn't recognize the data as a date, so i want to "Match Destination Formatting (M)" just like a right-click special paste. so this is what i tried:
Code:
'copy and paste the data
CopyData.Copy
addme.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
        False, NoHTMLFormatting:=True
and i get the error "Compile error: Named argument not found"
What am i doing wrong here? Thanks in advance! Also, this is only my second post so if i need to show more or less of my code, or something else to improve future postings please let me know. Thanks!
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hello

"addme" is a Range and your code is doing a "PasteSpecial" to the Worksheet from the clipboard. You need to first select the cell where the data is to be pasted from the clipboard and then perform the operation on the worksheet itself. The Parent property of a Range object returns the Worksheet to which it belongs.

Code:
'copy and paste the data
CopyData.Copy
addme.Select
addme.Parent.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
        False, NoHTMLFormatting:=True
 
Last edited:
Upvote 0
Hi Leith! thanks so much for the response! i entered that bit, now i have
Code:
'copy and paste the data
CopyData.Copy
addme.Select
addme.Parent.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
        False, NoHTMLFormatting:=True
but i'm getting :
"An Error has Occurred
The error number is: 1004
Select method of Range class failed
Please notify the administrator"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,400
Members
448,893
Latest member
AtariBaby

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