Results 1 to 8 of 8

Selected data from combo boxes to text boxes

Threaded View

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    11

    Selected data from combo boxes to text boxes

    Hi all

    First of all I would say I'm new to excel vba and know very little about it. Most of the macros I've ever used were copied and adapted by me.

    I've got a following problem.

    I have a table with some data, where "A","B" and "C" columns are more and more detailed description of a place. For example, "A1" = Europe, "B1" = England, "C1" = London.
    "D" column is a value (expenses in this particular place for a period of time). There are a significant amount of rows with different places (up to 200 yet)

    I've got 3 combo boxes with an available list of choices in the second and third depending on the choices in the previous ones. For example, if choose "Europe" in the first one, I can choose "France" or "England" etc. and then if I choose "England" I can go for "London", "Manchester" etc. Moreover, this data may repeat a few times. For example, there might be 5 "Europe" "England" "London" across the rows. The only difference will be in the value in "D" Column. I can continue these cascading combo boxes so I'm able to see all the values for a particular place across the rows. I've found a following code for that and adapted it a bit

    Private Sub UserForm_Initialize()
    'Load UserForm1
        Place Range([A2], [A2].End(xlDown))
    End Sub
    
    Sub Place(Data As Range)
        Dim d, cel As Range
        Set d = CreateObject("Scripting.Dictionary")
        For Each cel In Data
            On Error Resume Next
            d.Add cel.Text, cel.Text 'Add some keys and items
        Next
        ComboBox1.List() = d.items
    End Sub
    
    Private Sub ComboBox1_Change()
        ComboBox2.Clear
        'ComboBox2.TopIndex = ComboBox2.ListIndex
        Country Range([B2], [B2].End(xlDown))
    End Sub
    
    Sub Country(Data As Range)
        Dim d, cel As Range
        Set d = CreateObject("Scripting.Dictionary")
        For Each cel In Data
            If cel.Offset(, -1) = ComboBox1.Text Then
                On Error Resume Next
                d.Add cel.Text, cel.Text
            End If
        Next
        ComboBox2.List() = d.items
    End Sub
    
    Private Sub ComboBox2_Change()
        ComboBox3.Clear
        City Range([C2], [C2].End(xlDown))
    End Sub
    
    Sub City(Data As Range)
        Dim d, cel As Range
        Set d = CreateObject("Scripting.Dictionary")
        For Each cel In Data
            If cel.Offset(, -1) = ComboBox2.Text And cel.Offset(, -2).Text = ComboBox1.Text Then
                On Error Resume Next
                d.Add cel.Text, cel.Text
            End If
        Next
        ComboBox3.List() = d.items
    End Sub
    
    Private Sub ComboBox3_Change()
        ComboBox4.Clear
        Value Range([D2], [D2].End(xlDown))
    End Sub
    
    Sub Value(Data As Range)
        Dim d, cel As Range
        Set d = CreateObject("Scripting.Dictionary")
        For Each cel In Data
            If cel.Offset(, -1) = ComboBox3.Text And cel.Offset(, -2) = ComboBox2.Text _
                And cel.Offset(, -3) = ComboBox1.Text Then
                On Error Resume Next
                d.Add cel.Text, cel.Text
            End If
        Next
        ComboBox4.List() = d.items
    End Sub
    However, I wonder if it's possible to use a Text Box instead of the fourth Combo Box, so I could see all the values and not choose them. More over, I wonder If it's possible to show the values in the Text Box for the places, if 3rd and even 2nd combo boxes are not chosen (To see all the values for the "Europe" or "England", without choosing a particular city).

    Thank you so much much for your help in advance
    Hope it's not too onerous.
    Last edited by soulun; 08-21-2013 at 04:05 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Help with code for userform text boxes, combo boxes and excel
    By innerise in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2014, 09:07 AM
  2. I need a code for presence check to check multiple text boxes and combo boxes
    By Lee_wwfc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2013, 01:53 PM
  3. Combo Boxes / Text Boxes Not Updating
    By ckk403 in forum Excel General
    Replies: 4
    Last Post: 01-09-2012, 08:22 AM
  4. assigning data to lists boxes and combo boxes in userforms
    By weston.roberts in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-01-2011, 03:11 AM
  5. assigning data to lists boxes and combo boxes in userforms
    By weston.roberts in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-30-2011, 08:46 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