+ Reply to Thread
Results 1 to 6 of 6

Error 424 when including declaration

  1. #1
    Registered User
    Join Date
    03-25-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    3

    Error 424 when including declaration

    Hi,
    I have a weird problem with the following code. When the declaration of s is included, the program stops at the "For Each s" statement caliming to need an object. When I comment it out, the code runs error free and TypeName reports "s" to be of type "Worksheet".

    Why does the code fail when the declaration of s is included?


    Please Login or Register  to view this content.
    Last edited by bk1; 03-25-2012 at 02:28 PM. Reason: forgot to ask for notification

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Error 424 when including declaration

    I'm not sure if this is the reason but you definitely should rename your Sheets variable as this is the name of an existing Excel VBA collection so you may well get conflicts. Call it something else eg mySheets

  3. #3
    Registered User
    Join Date
    03-25-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Error 424 when including declaration

    Unfortunately, that did not help. However, I do agree with your general viewpoint :-)

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,953

    Re: Error 424 when including declaration

    Dim s as Variant
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    03-25-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Error 424 when including declaration

    Much obliged :-) Thanks!!! That did the trick.

    But why does it have to be a variant when each element of the array is a Worksheet object?Is this documented somewhere?

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,953

    Re: Error 424 when including declaration

    It's documented in Using Arrays in Help. You are iterating through a array, therefore, the control variable (element) must be of type Variant.
    This works, yours did not:
    Please Login or Register  to view this content.
    so does:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1