Solved

Excel Form List Box Populate With Dynamic Range Issue

Posted on 2012-03-14
6
303 Views
Last Modified: 2012-03-14
All,

I have an excel file with a sheet called bookings and a form call frmBookings.

The form is used to capture bookings for people and the resultant records are added to the "bookings" sheet.

I have already set up a named range for the people in the table as well as a Dynamic range name using the worksheet change event.

What I am wanting to do is populate the List Box on the form with the distinct names of the people stored in the table (sheet bookings).

I need this to occur each time the user opens the form or adds a record.

Can someone please help as I am stuck with it.

CF
Test.xls
0
Comment
Question by:creativefusion
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 500 total points
ID: 37719396
Hi,

Replace Userform_intialize codes with the following

Private Sub UserForm_Initialize()
    
    Dim CompName
    
    With Sheets("Bookings")
        CompName = UNIQUE(.Range("a1").CurrentRegion.Columns(1).Offset(1))
    End With
    
    txtName.Value = ""
    txtPhone.Value = ""
    With cboDepartment
        .AddItem "Sales"
        .AddItem "Marketing"
        .AddItem "Administration"
        .AddItem "Design"
        .AddItem "Advertising"
        .AddItem "Dispatch"
        .AddItem "Transportation"
    End With
    cboDepartment.Value = ""
    With cboCourse
        .AddItem "Access"
        .AddItem "Excel"
        .AddItem "PowerPoint"
        .AddItem "Word"
        .AddItem "FrontPage"
    End With
    cboCourse.Value = ""
    optIntroduction = True
    chkLunch = False
    chkVegetarian = False
    Me.ListBox1.List = CompName
    
    txtName.SetFocus
End Sub
Function UNIQUE(ByRef r As Range)
    Dim v, i As Long
    
    v = r.Value2
    With CreateObject("scripting.dictionary")
        .comparemode = 1
        For i = 1 To UBound(v, 1)
            If Len(v(i, 1)) Then .Item(Trim$(v(i, 1))) = Empty
        Next
        If .Count Then UNIQUE = .keys
    End With
End Function

Open in new window


Kris
0
 

Author Comment

by:creativefusion
ID: 37719425
Hi and thanks for your suggestion.

Just to clarify please.

What is CompName = UNIQUE(.Range("a1").CurrentRegion.Columns(1).Offset(1))

Where is Current Region in the range names? Do I need to create this? If so, please specify.
0
 
LVL 18

Expert Comment

by:krishnakrkc
ID: 37719458
You could replace that line with

CompName = UNIQUE(Range("CourseName"))

CurrentRegion is hte property of range.

Kris
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:creativefusion
ID: 37719496
Okay. Thanks and got that.

I replaced my initialize code with yours and amended the range name from CurrentRegion to CourseName and I get an error.

Run Time Error '438':
Onject doesn't support this method.

??
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37720036
(Not for points)

"and amended the range name from CurrentRegion to CourseName and I get an error."

CurrentRegion is not a range name, it's a property of the Range object (it's basically what you get by selecting a cell and pressing Ctrl+A - i.e. the whole table enclosing that cell.)

You should be using the line that Kris posted last.
0
 

Author Closing Comment

by:creativefusion
ID: 37722735
Great help. Thanks.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question