+ Reply to Thread
Results 1 to 5 of 5

dim not working on multiple ranges

  1. #1
    Registered User
    Join Date
    03-18-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    1

    dim not working on multiple ranges

    I must be doing something basic wrong.

    Please Login or Register  to view this content.
    I get an error only for c, that the object variable or with block variable is not set.

    if I change the dim line to
    dim a, b, c, d as range and never use variable d, then the macro runs as I expect with no errors.

    Can anyone explain? Visual Basic 6.5 in Excel 2003.
    Last edited by royUK; 03-18-2010 at 03:06 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: dim not working on multiple ranges

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: dim not working on multiple ranges

    You use Set with Objects
    Please Login or Register  to view this content.
    I have added Code Tags in your post

  4. #4
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: dim not working on multiple ranges

    Only the last Variable is being designated as a Range. The preceding variables are variants by default. the whole Dim line does not receive the designation at the end of the line.
    Because of this, a=Cells(1,1) is assigning the value of the cell to the variable. To assign a range to a variable, you have to use Set as in: Set c= Cells(1,1).

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: dim not working on multiple ranges

    In other words, your complete code should be:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

+ 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