PasteSpecial Error

S

sowetoddid

I have been trying to run this macro but continue to get a "PasteSpecia
Method of Range Class Failed" error. Any ideas?


Sub testIt()
Dim ThisWB As Workbook, OpenedWB As Workbook, _
OpenFileName As Variant
Set ThisWB = ThisWorkbook
OpenFileName = Application.GetOpenFilename()
If LCase(TypeName(OpenFileName)) = "boolean" Then
Else
Set OpenedWB = Workbooks.Open(OpenFileName)
OpenedWB.Sheets(1).Range("A1:Z100").Copy
ThisWB.Worksheets("sheet1").Range("b1").PasteSpecial _
xlPasteValuesAndNumberFormats
OpenedWB.Close False
End If
End Su
 
G

GJones

Maybe the xlPasteValuesAndNumberFormats call is generating
an error because some of the values are not numbers
 
B

Bob Phillips

I suggested earlier that it was because the target worksheet was not
selected. Did you try that?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
S

sowetoddid

I removed the AndNumberFormats and the code worked. You are right,
also have a little bit of text in the copied file
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top