Solved

Excel Form List Box Populate With Dynamic Range Issue

Posted on 2012-03-14
6
281 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now