+ Reply to Thread
Results 1 to 2 of 2

problem with Range statement in With-End With loop

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    problem with Range statement in With-End With loop

    In the sub below the following code gives an error.

    Please Login or Register  to view this content.
    The problem is definetely with this line, because if I specify the Range to Range("D:D") the sub is working.
    What is wrong here?
    I attached a test Excel sheet with the macro.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by dschmitt; 04-22-2010 at 04:24 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: problem with Range statement in With-End With loop

    Untested but basically in this context you would either need to use:

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    using the latter is obviously simpler - using the former it would generally be a good idea to assign the sheet object to a variable so you can use shorthand reference.

    (in essence each range object used must be qualified against the parent sheet object - Sheets("z").Range("D:D") works because you have one range object - using Range(Cells,Cells) you have three)

+ 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