What is wrong with this?

06-20-2005, 02:12 AM
Hi, I could not see why it gets error.
It gives "object" error at the point written in bold.

With Workbooks("A.XLS").Worksheets("A")
.Range(Cells(2, 9), Cells(2, 11)).Value = .Range(Cells(3, 9), Cells(3, 11)).Value
End With


06-20-2005, 03:18 AM
You refer to "Cells" from which workbook/sheet... ;)

So, in your code "Cells(2, 11)).Value" for instance will refer to the active sheet, no matter which one it is. If you don't want that to happen you'll have to put a dot in front of it:

With Workbooks("A.XLS").Worksheets("A")
.Range(.Cells(2, 9), .Cells(2, 11)).Value = .Range(.Cells(3, 9), .Cells(3, 11)).Value
End With


06-20-2005, 09:53 AM
Try the following:

Range(.Cells(2, 9), .Cells(2, 11)).Value = Range(.Cells(3, 9), .Cells(3, 11)).Value
Qualify the ranges passed in the Range reference, but not the outer Range, it knows what to do from there. :)

06-20-2005, 04:44 PM
Thank you for all worthy replies.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum