Solved

Excel Form List Box Populate With Dynamic Range Issue

Posted on 2012-03-14
6
313 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
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…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

839 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