VBA Module Calling Userform and Populating

Theo71

New Member
Joined
Jun 24, 2003
Messages
8
I am trying to set up a form to display data from various worksheets and to allow data entry to update across worksheets.

The following code resides under module1 but it fails to populate data into the listbox when I run it. I am new to the activeworkbook.names.add function, I am probably not using correctly, can some one help.


Sub present_form()

MsgBox " Hi form process "
Sheet6.Activate
lastrow = Range("A600").End(xlUp).Row
ActiveWorkbook.Names.Add Name:="listCourses", RefersTo:="=Sheet6!$A$2:$A$" & lastrow
MsgBox "lastrow " & lastrow
frmRound.lstCourses.Value = listCourses

frmRound.lblCourse.Caption = "Courses Listed in " & Sheet6.Name

frmRound.Show
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You need the rowsource:
Code:
frmRound.lstCourses.rowsource = "listCourses"
or list:
Code:
frmRound.lstCourses.list = [listCourses]
 
Upvote 0
Thanks but no joy.
I get run time errors referring to array index and invalid property value.

When I code the listCourses without the double quotes it executes error free but listbox remains unpopulated.
Debugging reveals that the listCourses is empty? I don't think my list is being picked up even though there are 28 rows of data in sheet6



Code:
frmRound.lstCourses.rowsource = listCourses
 
Upvote 0
Is sheet6 the tab name, or the code name?
 
Upvote 0
Sheet6 is the code name.

I have been searching the web, I failed to mention that I am running Excel 2003. I believe rowsource might not be the way to go.

I have created a combo box instead of a list box and managed to load the data in from sheet6.

The new issue is that there are 3 columns on the worksheet, but on the combo text when I select an item off the drop down it only shows the first column.
I will need to pick up all 3 columns in subsequent processing.

Code:
Private Sub UserForm_Initialize()
   
    Sheet6.Activate
    
    MsgBox ActiveSheet.CodeName
    cboCourses.List = Range("a2:c28").Value
   
    frmRound.lblCourse.Caption = "Courses Listed in " & Sheet6.Name
    
    
End Sub
 
Upvote 0
Have you set the ColumnCount of the combobox to 3?
 
Upvote 0
FYI your original didn't work because the Name requires the tab name, not the code name.
 
Upvote 0
Thanks Rorya the rowsource worked with the tab name.
I wanted to use the code name because the user might change the tab name in future.

Norie, yes I did have the columncount of the combobox = 3
I also set the Style property to 0, and entered Text to appear at the top of the combobox. All other properties set to the defaults.
In the drop down section of the combo box all 3 columns from the worksheet appear for each line.

After clicking one of the lines only the first column appears in the text.
combobox.value only contains the first of 3 items.

I will need to use the other 2 columns after clicking. Maybe my approach is wrong.
In VB6 I used a DataGrid which was like an array and you could work with each column as a separate field. Does Excel VBA have something similar in userforms?

Sorry if my VBA terminology is not good.
 
Upvote 0
To use the code name, you can use:
Code:
Sheet6.Range("A2:A" & lastrow).Name = "listSource"
for example.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top