+ Reply to Thread
Results 1 to 15 of 15

loop controls in userform except one textbox

  1. #1
    Registered User
    Join Date
    03-17-2010
    Location
    Belgium
    MS-Off Ver
    Excel 2016
    Posts
    12

    loop controls in userform except one textbox

    Hello there,

    I am using a userform where i have my textboxes, comboboxes with a commandbutton.
    When i click on that commandbutton, i would like to reset all the textboxes except one of them.
    Currently i am using the following code i got from the internet. But how can I have one of my textboxes unchanged on the userform?

    Please Login or Register  to view this content.
    Thanks

    gkisacik
    Last edited by gkisacik; 03-28-2010 at 03:18 AM.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,601

    Re: loop controls in userform except one textbox

    Hi gkisacik,

    please use CODE tag around your code.

    Go to post -> Edit -> Go advanced -> select your code and use # sign around it

  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: loop controls in userform except one textbox

    Use the TextBox Tag Property, give the TextBox to exclude a value then this code will work
    Please Login or Register  to view this content.
    Hope that helps.

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

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    03-17-2010
    Location
    Belgium
    MS-Off Ver
    Excel 2016
    Posts
    12

    Re: loop controls in userform except one textbox

    Hello RoyUk,

    Not sure it works that way.
    To make it clear;
    I have textboxes like; txtpercentage1, txtpercentage2, txtpercentage3...
    then i have a textbox like txttrial
    I would like to have txttrial out of that loop to be set to "".

    How can i fix this?

    Thanks
    gkisacik

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: loop controls in userform except one textbox

    Try this in Roys' Code change

    Please Login or Register  to view this content.
    To

    Please Login or Register  to view this content.

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

    Re: loop controls in userform except one textbox

    Why not try the code,add anything to the Tag property of txttrial, say x. Then run the code

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: loop controls in userform except one textbox

    Apologies Roy.

    I should have first said that your code works perfectly well.

  8. #8
    Registered User
    Join Date
    03-17-2010
    Location
    Belgium
    MS-Off Ver
    Excel 2016
    Posts
    12

    Re: loop controls in userform except one textbox

    Hello Marcol,

    For txttrial it works fine but not for the other textboxes (txtpercentage1, txtpercentage2...)

    Any other suggestion?

    Thanks
    gkisacik

  9. #9
    Registered User
    Join Date
    03-17-2010
    Location
    Belgium
    MS-Off Ver
    Excel 2016
    Posts
    12

    Re: loop controls in userform except one textbox

    sorry that i forgot to mention. even with RoyUK's code the textboxes dont get set to "".

    I am sending you now the full code; Any suggestion is welcome.

    Please Login or Register  to view this content.

  10. #10
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: loop controls in userform except one textbox

    What are you asking?

    txtpercentage1 = "", txtpercentage2 = "", txtpercentage3 = ""............

    txttrial = "some text"

    If so BOTH variations of the code work.

    Are you wanting to exclude other controls, for instance Labels?

    EDIT:

    Posted before I saw your code.
    Last edited by Marcol; 03-27-2010 at 05:31 PM. Reason: Forgot to refresh browser

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: loop controls in userform except one textbox

    Your code as supplied has two If statements with no End If

    I have no idea where this should be fixed, only you know that

    Change the code block to

    Please Login or Register  to view this content.
    Depending on where your If statements end, you may not need these two lines


    Please Login or Register  to view this content.
    Last edited by Marcol; 03-27-2010 at 05:38 PM. Reason: typos

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

    Re: loop controls in userform except one textbox

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

    The reason that I suggested using the Tag property is that it is easier to maintain, you can add the exception to other TextBoxes or remove it easily this way.

    Also,Select case is much easier to follow.

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

    Re: loop controls in userform except one textbox

    I pasted incorrectly in the first post, my code should be
    Please Login or Register  to view this content.
    I can't really see why you need to clear labels

    Well spotted Marcol
    Last edited by royUK; 03-28-2010 at 04:30 AM.

  14. #14
    Registered User
    Join Date
    03-17-2010
    Location
    Belgium
    MS-Off Ver
    Excel 2016
    Posts
    12

    Re: loop controls in userform except one textbox

    Hey Thanks RoyUK,

    yesterday i could not see it anymore. I wanted to sleep over and start with fresh brains :-).

    But with your last post, the code worked better.

    Thank you very much
    gkisacik

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

    Re: loop controls in userform except one textbox

    No problem

+ 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