Simple variable assignment in Excel 2003 VBA

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-14T02:37:49Z Indexed on 2010/03/14 2:45 UTC
Read the original article Hit count: 394

Filed under:

Hi,

I am new to VBA in Excel. I'm setting up a simple macro

Option Explicit

Sub Macro1()
   Dim sheet
   sheet = Worksheets.Item(1)  ' This line has the error
End Sub

On the line with the error, I get "Run-time error '438' Object doesn't support this property or method"

I can use the Watch window to see that "Worksheets.Item(1)" is a valid object. I've tried changing it to "Dim sheet As Worksheet" but same result.

Ok, so what am I missing? Why does this error occur?

Thanks!

-Mike

© Stack Overflow or respective owner

Related posts about excel-vba