+ Reply to Thread
Results 1 to 5 of 5

Why Form Combobox VBA do not fill the combobox? Please help!

Hybrid View

  1. #1
    Registered User
    Join Date
    05-23-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    19

    Unhappy Why Form Combobox VBA do not fill the combobox? Please help!

    Hi all,

    I am not sure where my script has gone wrong.

    See attached excel file.

    I am trying to have a few comboboxes which will return the quantity depending on the DATE, BARS.

    I have created the date without issue. However the Bars did not work because when I select the from the drop down list, the box appear blank.

    As well - how to write a script that if a particular bar is selected, what Items did they order using vertical data to appear horizontally and has to be Unique list too?

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Why Form Combobox VBA do not fill the combobox? Please help!

    To add items in combobox, do the following:

    Double click the userform to go into the VBA window of the userform. There are 2 dropdown boxes at the top of the window, one is named "userform" and one is named "click". Change the click to "Initialize". Once you do it, this code will show in the window:

    Private Sub UserForm_Initialize()
    
    
    End Sub
    Here is where you will add the items:

    Private Sub UserForm_Initialize()
    with combobox1
    .additem "Item 1"
    .additem "Item 2"
    .additem "Item 3"
    end with
    
    
    End Sub

  3. #3
    Registered User
    Join Date
    05-23-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    19

    Re: Why Form Combobox VBA do not fill the combobox? Please help!

    Thanks kjy1989 but it did not work nor I can find the UserForm_Initialize()

    I am not using UserForm. I created comboboxes using Form and assigned macro to it with VB script.

  4. #4
    Registered User
    Join Date
    05-23-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    19

    Re: Why Form Combobox VBA do not fill the combobox? Please help!

    Code as below

    Sheet2(Sheet2)
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Not Intersect(Target, Range("$A:$A")) Is Nothing Then
         Call FilterUniqueDate
        End If
    
    End Sub
    
    Private Sub Worksheet_ChangeBARS(ByVal Target As Range)
    
        If Not Intersect(Target, Range("$B:$B")) Is Nothing Then
         Call Bars_ID
        End If
    
    End Sub

    Module 2
    Sub FilterUniqueDate()
        Dim Lrow As Long, test As New Collection
        Dim Value As Variant, temp() As Variant
        ReDim temp(0)
        On Error Resume Next
        With Worksheets("Sheet2")
            Lrow = .Range("A" & Rows.Count).End(xlUp).Row
        temp = .Range("A2:A" & Lrow).Value
        End With
        For Each Value In temp
            If Len(Value) > 0 Then test.Add Value, CStr(Value)
        Next Value
        Worksheets("Sheet2").Shapes("UniqueDate").ControlFormat.RemoveAllItems
        For Each Value In test
             Worksheets("Sheet2").Shapes("UniqueDate").ControlFormat.AddItem Value
        Next Value
        Set test = Nothing
    End Sub
    Sub SelectedValueDate()
        With Worksheets("Sheet2").Shapes("UniqueDate").ControlFormat
            Worksheets("Sheet2").Range("J6") = .Value
            
        End With
    End Sub
    Module 3
    Sub Bars_ID()
        Dim Lrow As Long, test As New Collection
        Dim Value As Variant, temp() As Variant
        ReDim temp(0)
        On Error Resume Next
        With Worksheets("Sheet2")
            Lrow = .Range("B" & Rows.Count).End(xlUp).Row
        temp = .Range("B2:B" & Lrow).Value
        End With
        For Each Value In temp
            If Len(Value) > 0 Then test.Add Value, CStr(Value)
        Next Value
        Worksheets("Sheet2").Shapes("BarsID").ControlFormat.RemoveAllItems
        For Each Value In test
             Worksheets("Sheet2").Shapes("BarsID").ControlFormat.AddItem Value
        Next Value
        Set test = Nothing
    End Sub
    
    Sub SelectedValueBars()
        With Worksheets("Sheet2").Shapes("BarsID").ControlFormat
            Worksheets("Sheet2").Range("J8") = .List(.Value)
        End With
    End Sub

  5. #5
    Forum Contributor
    Join Date
    03-14-2012
    Location
    location
    MS-Off Ver
    Excel 2007
    Posts
    170

    Re: Why Form Combobox VBA do not fill the combobox? Please help!

    Hi Alex,
    something similar you can find here, I saw it earlier, perhaps you need to expand it to give the "fruits" when you find/choose the airport
    http://www.excelforum.com/excel-prog...betically.html
    blue

+ 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. [SOLVED] Can't get combobox to properly fill data based on another combobox.
    By Orestees in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-15-2012, 05:22 PM
  2. Calling a user form initialize sub when entering the form to populate combobox...
    By regupnorth in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-02-2012, 07:24 AM
  3. Transfer User form data to a worksheet w.r.t. combobox item on the form
    By nm766 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2011, 12:43 PM
  4. transferring combobox value from one user form to populate combobox on another
    By smartphreak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2010, 10:12 PM
  5. [SOLVED] Fill a combobox on a form from a txt file
    By Daniel Bonallack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2005, 03:06 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