+ Reply to Thread
Results 1 to 5 of 5

populate values into textbox on userform based on multiple combobox and two optionbuttons

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    758

    populate values into textbox on userform based on multiple combobox and two optionbuttons

    hello
    I have this file contains three combobox each other depends on other and I have two optionbutton I would when I select optionbutton (usd) then populate the price in textbox1 from column e for specific item after select from the three combobox and
    if i select optionbutton (lyd) then populate the price in textbox1 from column d for specific item after select from the three comboboxes
    note: the file contains code if this is not suitable I accept alternative
    thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: populate values into textbox on userform based on multiple combobox and two optionbutt

    First select option1 or 2 then select choose from combo 1 with this code

    Private Sub ComboBox1_Click()
    Dim rng As Range, col As Integer
    If OptionButton1 Then
        col = 3
    ElseIf OptionButton2 Then
        col = 4
    Else
        MsgBox "First select LYD or USD"
        ComboBox1.ListIndex = -1
        Exit Sub
    End If
    With Sheets("Brand").Range("A:A")
        Set rng = .Find(ComboBox1.List(ComboBox1.ListIndex, 0), _
            lookat:=xlWhole, _
            searchorder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False)
            If Not rng Is Nothing Then
                ComboBox2.AddItem Sheets("Brand").Range("B" & rng.Row).Value
                ComboBox3.AddItem Sheets("Brand").Range("C" & rng.Row).Value
                TextBox1 = Sheets("Brand").Range("A" & rng.Row).Offset(, col).Value
            End If
    End With
    ComboBox2.ListIndex = 0
    ComboBox3.ListIndex = 0
    End Sub

    Kind regards
    Leo

  3. #3
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    758

    Re: populate values into textbox on userform based on multiple combobox and two optionbutt

    perfect leo jut i want a little amending if is possible when select option 1 and select item from combobox1 is ok but when I select option2 to the same item nothing change I have to change item to see change

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: populate values into textbox on userform based on multiple combobox and two optionbutt

    Replace whole code in UserForm code module with the following code.
    Option Explicit
    Private dic As Object
    
    Private Sub UserForm_Initialize()
        Dim a, i As Long, ii As Long
        Set dic = CreateObject("Scripting.Dictionary")
        With Sheets("brand").Cells(1).CurrentRegion
            a = .Parent.Evaluate(.Address & "&""""")
        End With
        For i = 2 To UBound(a, 1)
            If Not dic.exists(a(i, 1)) Then
                Set dic(a(i, 1)) = CreateObject("Scripting.Dictionary")
            End If
            If Not dic(a(i, 1)).exists(a(i, 2)) Then
                Set dic(a(i, 1))(a(i, 2)) = CreateObject("Scripting.Dictionary")
            End If
            dic(a(i, 1))(a(i, 2))(a(i, 3)) = Array(a(i, 4), a(i, 5))
        Next
        Me.ComboBox1.List = dic.keys
    End Sub
    
    Private Sub ComboBox1_Click()
       Me.ComboBox2.Clear
       Me.ComboBox3.Clear
       Me.ComboBox2.List = dic(Me.ComboBox1.Value).keys
       GetPrice
    End Sub
    
    Private Sub ComboBox2_Click()
       Me.ComboBox3.Clear
       Me.ComboBox3.List = dic(Me.ComboBox1.Value)(Me.ComboBox2.Value).keys
       GetPrice
    End Sub
    
    Private Sub ComboBox3_Click()
       GetPrice
    End Sub
    
    Private Sub TextBox1_AFTERUPDATE()
        With Me.TextBox1
            If IsNumeric(.Value) Then .Value = Format(.Value, "$#,##0.00")
        End With
    End Sub
    
    Private Sub OptionButton1_Click()
        GetPrice
    End Sub
    
    Private Sub OptionButton2_Click()
        GetPrice
    End Sub
    
    Private Sub GetPrice()
        Dim i As Long, myCol As Long
        Me.TextBox1 = ""
        For i = 1 To 3
            If Me("combobox" & i).ListIndex = -1 Then Exit Sub
        Next
        If Not dic.exists(Me.ComboBox1.Value) Then Exit Sub
        If Not dic(Me.ComboBox1.Value).exists(Me.ComboBox2.Value) Then Exit Sub
        If Not dic(Me.ComboBox1.Value)(Me.ComboBox2.Value).exists(Me.ComboBox3.Value) Then Exit Sub
        For i = 1 To 2
            If Me("optionbutton" & i) Then Exit For
        Next
        If i < 3 Then Me.TextBox1 = Format$(dic(Me.ComboBox1.Value)(Me.ComboBox2.Value)(Me.ComboBox3.Value)(i - 1), "$#,##0.00")
    End Sub

  5. #5
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    758

    Re: populate values into textbox on userform based on multiple combobox and two optionbutt

    great achievement ! many thanks mr.Jindon ​​​​

+ 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: 1
    Last Post: 08-31-2020, 03:36 AM
  2. Populate textbox based on combobox selection on Userform
    By Abdur_rahman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2019, 02:07 AM
  3. [SOLVED] Textbox - populate with month name and values based on Combobox selection
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-02-2015, 08:09 AM
  4. Replies: 11
    Last Post: 04-11-2015, 05:48 PM
  5. Calculating/adding userform textbox values based on combobox selection and display to cell
    By SpreadsheetGirl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-04-2015, 08:57 AM
  6. Populate userform from row values based on combobox
    By robertogavilan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2014, 06:32 PM
  7. [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

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