+ Reply to Thread
Results 1 to 4 of 4

With.........End With

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    With.........End With

    Dear Forum Members

    Can you nest With......End With clauses.
    I want to populate a userform from a worksheet and would like to code

    Please Login or Register  to view this content.
    but I can't
    Can someone please help?
    John
    Last edited by j_Southern; 02-11-2011 at 09:35 AM.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: With.........End With

    Hi,

    Not with the effect you want. The innermost "With Object" will be applied by the compiler so, in this case, it will interpret TextBox1 belong to Sheet1 and not Userform1.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: With.........End With

    Colin Legg
    Ah well, I,ll just have to continue typing. Thanks for your help though it stops me from fruitlessly searching.
    John

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: With.........End With

    Of course, one thing you can do (and it helps if you have to make amendments to the sheet name your code because you only have to do it in one point), is hold a reference to the object in a variable.

    eg.

    Instead of this:
    Please Login or Register  to view this content.


    You could use this:
    Please Login or Register  to view this content.
    And then you could introduce your With.... End With block if you wanted to (I wouldn't in this case):
    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