Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel Form List Box Populate With Dynamic Range Issue

Posted on 2012-03-14
6
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

688 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