+ Reply to Thread
Results 1 to 4 of 4

Dynamic Combobox

  1. #1
    Registered User
    Join Date
    05-23-2013
    Location
    cambridge
    MS-Off Ver
    Excel 2003
    Posts
    12

    Dynamic Combobox

    Hi

    I would greatly appreciate some appreciate some help from the experts in this forum, please help if you can.
    I am trying to make the listing range for a combobox dynamic. The combobox listing ranges change depending on the value of a cell.
    i have 3 listing ranges for one combobox, the ranges are factory1, factory2, factory3, all these ranges are static and i would like to make them dynamic.
    i have attached an example file. below is the code i am using:
    [Sub MAIN()
    Dim PT As Range
    Dim i As Long
    With ActiveSheet
    setNames .Range("a6")
    Set PT = .Range("b1")
    i = 1
    Do Until PT = ""
    If .Range("a1").Value = PT.Value Then
    On Error Resume Next
    .ComboBox1.ListFillRange = ThisWorkbook.Names("factory" & i).RefersToRange.Address
    If Err.Number = 1004 Then
    MsgBox "not defined name: factory" & i
    ElseIf Err.Number <> 0 Then
    MsgBox "unexpected error: " & Err.Description
    End If
    On Error GoTo 0
    End If
    i = i + 1
    Set PT = PT.Offset(0, 1)
    Loop
    End With
    End Sub

    Sub setNames(theTopLeft As Range)
    Dim theName As Name
    Dim nameStr As String
    Dim theRng As Range
    Dim i As Long
    Application.DisplayAlerts = False
    theTopLeft.CurrentRegion.CreateNames Top:=True, Left:=False, _
    Bottom:=False, Right:=False
    Application.DisplayAlerts = True
    For Each theName In ThisWorkbook.Names
    With theName.RefersToRange
    For i = .Cells.Count To 1 Step -1
    If .Cells(i) <> "" Then Exit For
    Next
    End With
    If i <> 0 Then theName.RefersTo = theName.RefersToRange.Resize(i, 1)
    Next
    End Sub][/CODE]
    Attached Files Attached Files

  2. #2
    Forum Contributor BeachRock's Avatar
    Join Date
    11-01-2011
    Location
    Oregon, United States
    MS-Off Ver
    Excel 2016
    Posts
    403

    Re: Dynamic Combobox

    Hi tamzgha,

    You might want to take a look at this: http://www.exceltip.com/excel-genera...t-problem.html

    I use them all the time and they work fantastic.
    -------------
    Tony

  3. #3
    Registered User
    Join Date
    05-23-2013
    Location
    cambridge
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Dynamic Combobox

    Thanks a lot!
    I used the OFFSET and it worked

  4. #4
    Forum Contributor BeachRock's Avatar
    Join Date
    11-01-2011
    Location
    Oregon, United States
    MS-Off Ver
    Excel 2016
    Posts
    403

    Re: Dynamic Combobox

    Glad I could help.

    Make sure to mark the thread as solved if your question was answered. Use the menu "Thread Tools" at the top of your first post and select "Mark this thread as solved".

+ 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. Combobox source , linked to other combobox value ??(DYNAMIC)
    By stevnb in forum Excel Programming / VBA / Macros
    Replies: 40
    Last Post: 01-25-2013, 05:28 AM
  2. Dynamic Combobox help
    By akira115 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2012, 01:49 PM
  3. Dynamic Combobox
    By Mahe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2010, 10:12 AM
  4. dynamic combobox
    By john_t_h in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-14-2005, 10:05 AM
  5. dynamic combobox
    By soasi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-13-2005, 10:00 PM

Tags for this Thread

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