+ Reply to Thread
Results 1 to 9 of 9

Clear Multiple Textboxes on a Userform

  1. #1
    Registered User
    Join Date
    11-30-2012
    Location
    North Carolina
    MS-Off Ver
    Office 365
    Posts
    60

    Clear Multiple Textboxes on a Userform

    I have a multipage user form. Each page has multiple textboxes. I have written VBA code, triggered by a command button, to copy the code to another sheet in the workbook. This code works fine. In the same sub, i have code that clears the value of each textbox (Me.MB50101.Value = ""). This works fine, but it seems to me that clearing the textboxes can be done more efficiently. I found a bit of code that presumably loops through all textboxes on a single page of the userform and clears the code:

    Please Login or Register  to view this content.
    The code does not throw an error but also does not clear the textboxes. I believe my error is the use of wildcards in the TypeName. There are three potential formats for the names of the textboxes:

    MB50101 - The first two letters and last two numbers can change (body cells)
    MB501Total - The first two letters can change (column total)
    GTotal50101 - The last two letters can change (row total)

    is there is single "*501##*" that can address this? If so, i cannot figure this out. Otherwise, do i need multiple if then conditions? Also, this code was triggered by a separate command button; i want to embed this code in the macro that copies the values to the separate sheet.

    The "501" embedded in the textbox name identifies all textboxes on Page 1 of the userform. Page two textboxes use 502; Page three, 503, etc.

    Appreciate any wisdom that can be provided.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Clear Multiple Textboxes on a Userform

    Untested because you did not post a sample.

    Please Login or Register  to view this content.

    This is tested and works:

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 03-02-2020 at 09:11 AM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,295

    Re: Clear Multiple Textboxes on a Userform

    As it is often needed more than once within an app., my usual practice is to put this in a module and call it as needed.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-30-2012
    Location
    North Carolina
    MS-Off Ver
    Office 365
    Posts
    60

    Re: Clear Multiple Textboxes on a Userform

    My apologies; in the future i will post a sample so that proposed solutions can be tested before the experts respond.

  5. #5
    Registered User
    Join Date
    11-30-2012
    Location
    North Carolina
    MS-Off Ver
    Office 365
    Posts
    60

    Re: Clear Multiple Textboxes on a Userform

    To both responders, thank you. Torachan's response is more appropriate as i will need to clear entries on all pages of the userform. Thus calling the procedure will an idea i had not thought of yet but appropriate. That solution works.

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Clear Multiple Textboxes on a Userform

    Not to be out done:

    The following is my standard code for loading from a worksheet to a Userform and saving data from the Userform to the sheet.

    Each Control must retain standard names and must be numbered for the column where its data is stored.

    You can have multiple controls with the same number.

    So If Your UserID is in Column 1. then If they exist then Combobox1, Label11, Listbox1, Textbox will all be loaded with the UserID.

    These codes will can or save hundreds of controls without issue.

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,891

    Re: Clear Multiple Textboxes on a Userform

    Can you upload the sample file?.
    Last edited by Phuocam; 03-05-2020 at 10:46 PM.

  8. #8
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,401

    Re: Clear Multiple Textboxes on a Userform

    Quote Originally Posted by lateniteNC1 View Post
    Please Login or Register  to view this content.
    Untested, but does it work if you change the red highlighted line of code to this...

    If z.Name Like "*501##*" Then

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Clear Multiple Textboxes on a Userform

    Obviously.

    If you select an empty row and load your Userform with the data there. Then the Userform is cleared:

    Please Login or Register  to view this content.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 03-06-2020 at 05:27 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA userform multiple TextBoxes in one cell
    By baxius in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2020, 08:59 AM
  2. Userform multiple textboxes
    By colddeck84 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2017, 02:22 PM
  3. [SOLVED] IF multiple textboxes in Userform = Nothing
    By Catsonheat in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-16-2017, 05:48 PM
  4. VBA Userform Multiple Textboxes to Find Record
    By chamowllie01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-07-2016, 10:06 AM
  5. Format Multiple Textboxes at once in a Userform
    By Dan... in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2015, 05:34 PM
  6. Formatting Multiple Userform Textboxes
    By badeye in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-01-2010, 09:14 AM
  7. [SOLVED] UserForm TextBoxes (with ControlSource set) won't clear in one click
    By Paul Martin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2005, 08:06 AM

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