+ Reply to Thread
Results 1 to 7 of 7

Userform Macro need minor adjustments to code (Populate Textbox and Combobox Return Issue)

  1. #1
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Userform Macro need minor adjustments to code (Populate Textbox and Combobox Return Issue)

    I have a userform which inputs data based upon a chosen item from a combobox. Combobox3 pulls numerical items from Rows17 and below in columnA of active worksheet. The first problem I am having is that the combobox itself is cutting numerical numbers short. Items go out to the thousandths (ex. 1.001) but in cases where there is a "0" at the end of the decimal it abbreviates it (ex.1.01) is there anyway to fix this? The second issue is I would like to populate "Textbox4" with the columnC content of the item chosen. (Ex. User choses Item 1.001 (found in row118) then Textbox4 would = the value of C18) Below is the current code utilized for this userform.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,124

    Re: Userform Macro need minor adjustments to code (Populate Textbox and Combobox Return Is

    Use the format function.
    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Userform Macro need minor adjustments to code (Populate Textbox and Combobox Return Is

    Quote Originally Posted by Tinbendr View Post
    Use the format function.
    Please Login or Register  to view this content.

    Tinbendr,

    Thanks worked as desired. Could you help with populating "Textbox4" with the columnC value based upon the columnA value chosen in the combobox?

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,124

    Re: Userform Macro need minor adjustments to code (Populate Textbox and Combobox Return Is

    Could you help with populating "Textbox4" with the columnC
    This is how I handle that. Comboboxes/listboxes can store up to 10 columns of data. We will take advantage of that and store the C value in column 1 (Column 0 is the first column) of the combobox right after we add the column A value.

    (BTW, step 1 in your loop is redundant. One is the default step value.)
    Please Login or Register  to view this content.
    Then, in the Combobox3_Change event, we will recall that C Value from the combobox and store it in the textbox.

    Please Login or Register  to view this content.
    (To me, the textbox is unnecessary unless you plan to edit the value and write it back to the sheet.)

    To hide the column 1 values in the combobox list, make the width of Column 0 the same width as the combobox.

  5. #5
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Userform Macro need minor adjustments to code (Populate Textbox and Combobox Return Is

    Quote Originally Posted by Tinbendr View Post
    This is how I handle that. .
    Tinbendr,

    It keeps giving me an error on the commandbutton which generates the userform (not in the userform code itself??). Below is the code within the userform:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,124

    Re: Userform Macro need minor adjustments to code (Populate Textbox and Combobox Return Is

    Where is the error?

    If Range("A" & Rows.Count).End(xlUp).Row) is less than 18, it will generate an error.

    You should test the lastrow to make sure it > 18.

    You should also test Me.ComboBox3.Listindex to make sure a drop value is selected.

    You should also fully qualify the lastrow sheet reference. It saves headaches down the road. Especially if you are referencing multiple sheets.

    You can use Activesheet, but that is volatile.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Userform Macro need minor adjustments to code (Populate Textbox and Combobox Return Is

    Quote Originally Posted by Tinbendr View Post
    Where is the error?

    If Range("A" & Rows.Count).End(xlUp).Row) is less than 18, it will generate an error.

    You should test the lastrow to make sure it > 18.

    You should also test Me.ComboBox3.Listindex to make sure a drop value is selected.

    You should also fully qualify the lastrow sheet reference. It saves headaches down the road. Especially if you are referencing multiple sheets.

    You can use Activesheet, but that is volatile.

    Please Login or Register  to view this content.
    Tinbendr,

    The problem I have with declaring the sheet name is that it changes names multiple times throughout the formation of the worksheet. This being said you would have to go in each time and adjust the code. That is why I chose to use activesheet.

+ 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. Trying to populate a userform combobox from a userform textbox
    By jtemp57 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2014, 03:33 PM
  2. [SOLVED] Excel Userform: Populate other controls (i.e. textbox & combobox) based on combobox select
    By MileHigh_PhD in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2013, 04:50 PM
  3. [SOLVED] How do I make a selection from a combobox on my VBA userform populate a textbox?
    By ChristianMba in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-16-2012, 01:08 PM
  4. UserForm TextBox and ComboBox selections populate SPECIFIC spreadsheet cells
    By ZIXILPLIX in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-23-2010, 02:45 AM
  5. Userform ComboBox populate using code?
    By Marc Cowlin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2006, 09:40 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