+ Reply to Thread
Results 1 to 12 of 12

Userform Textbox to populate with

  1. #1
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Userform Textbox to populate with

    Hi. There's a couple of Userforms i'm working on that appear one after the other, but which I'm having problems with. Hopefully someone can help.

    Userform1 is a basic search and find using the text the user enters in a text box, followed by 'ok' commandbutton.

    If a matching cell is found in the worksheet, the row is selected and the second userform asks for text via textbox2. This text will be placed in the end column of that row (column L) that was found to have the text input in Userform 1.

    What's important is that if on that row some text already exists in column L, that this appears in textbox2 allowing the user to modify it.

    I'm ok with the search and find :

    Please Login or Register  to view this content.


    But can anyone help with how I do the rest?

    Jules
    Last edited by Julesdude; 02-10-2010 at 12:06 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Userform Textbox to populate with

    Hi,

    Please Login or Register  to view this content.
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Userform Textbox to populate with

    Thanks for that Richard.

    How do I then get the edited text box to appear back in that same cell after an 'ok' commandbutton is clicked?

    I'd need to carry over the 'r' variable to populate back in that cell the edited content.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Userform Textbox to populate with

    Hi Jules,

    To some extent it depends on when you want this to happen. However try entering the relevant code below in the TextBox2 After Update event. Note that in this case the r variable will need to be declared outside the Command Button click event so that it can be used by any procedure in the same form.

    The complete code is below

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Userform Textbox to populate with

    Hmm, I'm having some problems and I think it's all because I've got a few command buttons on the go, so not quite sure how to transfer the variable to a commandbutton one.

    To recap:
    Userform1 asks user to enter text in textbox1. 'Ok' commandbutton is clicked.
    Textbox1 is used to search worksheet.
    If found, second userform(2) appears with the cell value appearing in textbox2.
    Upon another commandbutton click for userform2, Textbox2 value is then placed in that cell.

    Unfortunately I'm not quite sure how to communicate any variables between these subs and commandbutton executions

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Userform Textbox to populate with

    Hi,

    Why not simplify matters and just use one user form with two text boxes.

    In the Initialise event of the user form make the second text box invisible, and this becomes visible when Text Box 1 is completed

    Please Login or Register  to view this content.
    then in the Before Update of text box 1
    Please Login or Register  to view this content.
    and in the TextBox 2 Change event
    Please Login or Register  to view this content.
    [/CODE]

    HTH

  7. #7
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Userform Textbox to populate with

    Hi Richard, thanks yes it does simplify things and looks better.

    However, when textbox2 appears, it now doesn't contain anything in the referenced cell, should there already be a value in there, so that the user can use this and edit it.

    Also, it inputs only in the last row of the worksheet, and not in the row it found the item in the search. Please help if you can.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Userform Textbox to populate with

    Hi,

    Can you attach the workbook - anonymised if necessary.

    Regards

  9. #9
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Userform Textbox to populate with

    Apologies I realised a mistake I'd made - I hadn't changed the name of 'textbox1' in the .find phrase with the actual name of the object in my code, which is why it was blank and not populating correctly.

    It works fine, thank you very much!!

  10. #10
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Userform Textbox to populate with

    ...by the way, is there anyway to wrap this textbox or allow line breaks and to transfer these line breaks to that cell?

  11. #11
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Userform Textbox to populate with

    Hi,

    Have you made sure the cells in column L? are formatted to wrap text? The text box will pass word spaces through to the cell just as if you had manually entered to the cell.

    If you allow the user to create new lines, have you set the textbox MultiLine property to true?

    Regards

  12. #12
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Userform Textbox to populate with

    Ah, i didn't set it to TRUE. All done now and working! Thanks again.

+ 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