am I thinking right?

hitch_hiker

Active Member
Joined
Feb 21, 2012
Messages
294
I am trying to setup a 2 column combobox in a userform, the userform works, but the combobox does not load any data, the explanation on the site where I plagiarised the code from says to use 'Private Sub UserForm_Initialize()' but the code for the combobox comes up with 'Private Sub cboPart_Change()', I don't know how the cboPart_Change() got put in the code, but when I change it to 'UserForm_Initialise()' , I get a error #9 subscript our of range. do I need to change the "UserForm" to the actual name of the user form e.g. "frmProductList". or have I confused myself , and do I need to do something different?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
No, you don't have to use the name of the UserForm. Maybe it will help if you post your code that's not working and tell us which line causes the error.
 
Upvote 0
thanks Andrew,

Code:
Private Sub cboPart_Change()
'Private Sub UserForm_Initialize()
Dim cPart As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("'product list'") 'LookupLists = product list sheet name
For Each cPart In ws.Range("PartIDList") 'PartIDList
  With Me.cboPart
    .AddItem cPart.Value
    .List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value
  End With
Next cPart

'Next cLoc

Me.cboPart.SetFocus
'End Sub
Rem .. need to change "lookuplists" to product list
    Rem ... should be private sub userform_initialize()
    
        Rem [URL]http://www.contextures.com/xlUserForm02.html[/URL]
End Sub

this is the code associated with the combobox,

this is where the debugger takes me when it errors
Rich (BB code):
Sub ShowFormName()
    frmProductList.Show
End Sub

if the line reads " Private Sub cboPart_Change() " it brings up the user form with the combobox opens but there is no data in the combobox, if the line reads " 'Private Sub UserForm_Initialize() ", then I get subscript out of range

does this help ?
 
Upvote 0
This:

Code:
Set ws = Worksheets("'product list'")

should be:

Code:
Set ws = Worksheets("product list")

ie no single quotes. You need to use the UserForm_Initialize event procedure.
 
Upvote 0
Thanks Andrew,
I thought I needed the single quotes because the sheet was more than one word, need to study syntax again, thanks for you help
 
Upvote 0
now I get
run-time error 1004
method 'range' of object'_worksheet' failed
the debugger takes me to
Code:
Sub ShowFormName()
    frmProductList.Show
End Sub
I will look it up , but any advise would be great
 
Upvote 0
That probably means there's a problem in the initialize code.

Try putting with F9 on the first line of the code and running the form with F5.

Code execution should break where you put the breakpoint.

You can then step through it using F8 to find where the error is.

I think it might be here.
Code:
For Each cPart In ws.Range("PartIDList") 'PartIDList
 
Upvote 0
Apart from checking the code you should check that you have a named range called PartIDList.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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