Modifing example code

L

Leanne

Hi - Beginner at code here!

I have taken this sample code from
http://www.contextures.on.ca/xlUserForm01.html#SetUp (which was a great help)
and downloaded the sample for Enhanced User forms with Combo boxes but I am
stuck on how to modify the first part.

Private Sub UserForm_Initialize()
Dim cPart As Range "This is the part I cannot work out what to
change it to.
Dim cLoc As Range I cannot see anything in the sheet or the
form that
Dim ws As Worksheet refers to cPart"
Set ws = Worksheets("LookupLists") "This I understand along with the rest
that
would make sense when
I work out the first
part - I think"

For Each cPart In ws.Range("PartIDList")
With Me.cboPart
.AddItem cPart.Value
.List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value
End With
Next cPart

For Each cLoc In ws.Range("LocationList")
With Me.cboLocation
.AddItem cLoc.Value
.List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
End With
Next cLoc


If anyone could help that would be great.
 
M

Mike H

Hi,

The first 2 lines simply tell the code that
cPart
cLoc
are ranges of cells, they exist only within the code memory and not as named
ranges anywhere.

The are referred to again in the lines
For Each cPart In ws.Range("PartIDList")

In this line the code loops through every cell(cPart) in the named range
"PartIDList" and this you will need to create as a named range on your
worksheet and put into it the data you want to populate into the (I assume)
combobox called cboPart

Hope this helps

Mike
 
L

Leanne

Hi Mike,

Yeah thanks for that. I thought that is what it would refer to but I could
not find the range in the sheet that was called cPart - Hence my question.

Thanks I will give it a go and see how I get on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top