+ Reply to Thread
Results 1 to 10 of 10

UserForm: Textbox value load according to drop down list

Hybrid View

  1. #1
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    UserForm: Textbox value load according to drop down list

    Hi gurus,

    I have a userform that I need it to load the value in the textbox according to the dropdown list

    For example:
    If outlet ABC selected, it 3 textbox need to show the value in same row of ABC outlet.

    Beside that, there is two button I need it to function as well

    Save button:

    Save the textbox value according to the drop down list selected

    For example, ABC outlet selected and there if there is a changes of any 3 textbox, say Promoter name change from David to Dave the save button need to save according to the cell selected

    Delete button:

    Need to delete whole row of selected outlet

    Please refer attached file: New Book.xlsm

    May I know how to achieve this?

    Thank you.

  2. #2
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: UserForm: Textbox value load according to drop down list

    i found this more or less the same situation from:

    http://stackoverflow.com/questions/2...using-named-ra

    and I modify it to suit my current condition:
    Private Sub CommandButton2_Click()
    
    Unload Me
    
    End Sub
    Private Sub UserForm_Initialize()
    
    Dim WS1 As Worksheet
    Dim WS2 As Worksheet
    Dim WS3 As Worksheet
    Dim WS4 As Worksheet
    Dim WS5 As Worksheet
    Dim WS6 As Worksheet
    
    Set WS1 = Worksheets("MonthSummary")
    Set WS2 = Worksheets("WeekSummary")
    Set WS3 = Worksheets("DatabaseForm")
    Set WS4 = Worksheets("DatabasePO")
    Set WS5 = Worksheets("Setup")
    Set WS6 = Worksheets("Products")
    
    Dim range_a As Range
    
        For Each range_a In Worksheets("Setup").Range("OutletList")
          With Me.cmbOutlet
            .AddItem range_a.Value
            .List(.ListCount - 1, 1) = range_a.Offset(0, 1).Value
          End With
        Next range_a
    
    lbName = WS5.Cells(1, 2)
    lbSales = WS5.Cells(1, 3)
    lbCost = WS5.Cells(1, 4)
    
    End Sub
    
    Private Sub Data_Change()
        With Me.cmbOutlet
            If .ListIndex = -1 Then
                Me.tbName.Text = ""
                Me.tbSales.Text = ""
                Me.tbCost.Text = ""
            Else
                tbName.Text = .List(.ListIndex, 1)
                tbSales.Text = .List(.ListIndex, 2)
                tbCost.Text = .List(.ListIndex, 3)
            End If
        End With
    End Sub
    but it seems doesnt work with my multiple textbox

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: UserForm: Textbox value load according to drop down list

    Hi lazyserv,

    Find the attached where I've triggered your userform by a double click in Column A. Then look at the code behind the Setup form for the On_Change code. Each time you change the combo dropdown it will refresh the data. You can also now change an outlet name and it will add it to the list when you click on the save button.

    I hope this little example gives you some ideas on how to use uerforms and their events.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: UserForm: Textbox value load according to drop down list

    Hi MarvinP

    May I know is it possible for it to load on the form Load?

    Currently I need to double click column A to show the form.

    Can change it to when I click a button that use Macro to call the form?

    For example: I create a button name Show Form

    Sub ShowOutletSetup()
    
    OutletSetup.Show
    
    End Sub
    Once the form load it will show default ABC outlet.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: UserForm: Textbox value load according to drop down list

    Try this one.

  6. #6
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: UserForm: Textbox value load according to drop down list

    Quote Originally Posted by MarvinP View Post
    Try this one.
    Hi MarvinP

    May I know how can I delete the whole row based on the drop down list selected?

  7. #7
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: UserForm: Textbox value load according to drop down list

    In addition:

    How do I save the code to Accounting format for this code row?
    I already set the whole row in Accounting format

    Cells(RowNum, "D") = Me.tbCost
    Currently when Initialize I set the format to load as Currency style

    Dim Cost As Double
    Cost = 0
    
    tbCost = Format(Cost, "$#,##0.00")
    But when I save the form it show as number instead of accounting format

  8. #8
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: UserForm: Textbox value load according to drop down list

    it work like charm, but it doesn't save the cost as accounting format

    it just save as number, if you look at the book all the cost was set to accounting format

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: UserForm: Textbox value load according to drop down list

    I don't quite understand what you want with "save in accounting format".

    Maybe the text needs to be changed to numbers before saving? 6 the number and 6 the letter both look the same to us but Excel treats them differently. Perhaps a convert to number using VBA is what you need somewhere in your code? Perhaps a .Value or CDec() is needed on that last textbox before you stick it back on your worksheet?

  10. #10
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: UserForm: Textbox value load according to drop down list

    My apologize, I didnt notice the code should end .Value

    I added the code and now it work like charm!

    Thanks and +rep for solving my problem.

    Thank you!!!

+ 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. Replies: 11
    Last Post: 01-20-2015, 09:34 AM
  2. Userform List of Textbox names
    By Isaaq in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2014, 10:28 AM
  3. Replies: 2
    Last Post: 02-08-2014, 01:24 PM
  4. [SOLVED] Load last cell in Column C to Userform Textbox
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2012, 10:22 AM
  5. Load list of ftp files from directory into a userform?
    By ddanfleetwood in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2010, 02:03 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