View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default named range as rowsource

Yep.

You didn't use the correct procedure name.

Sub Userform_Initialize()

Me.Caption = "Pool Types"

With Me.lstPoolList
.RowSource _
= Worksheets("Table").Range("PoolTypes").Address(ext ernal:=True)
'.RowSource = "PoolTypes"
'.RowSource = Sheets("Table").Range("PoolTypes")
.BoundColumn = 1
.ColumnCount = 1
.ListStyle = fmListStyleOption
End With

End Sub

I didn't look at the other routines.

Karen53 wrote:

Hi Dave,

Here is my complete code for the form. This resides in the forms module.
I have the new value being obtained by a textbox when they click 'Save'.

Sub frmPoolTypes_Initialize()

Load frmPoolTypes

Me.Caption = "Pool Types"

With Me.lstPoolList
'.RowSource =
Worksheets("Table").Range("PoolTypes").Address(ext ernal:=True)
'.RowSource = "PoolTypes"
.RowSource = Sheets("Table").Range("PoolTypes")
.BoundColumn = 1
.ColumnCount = 1
.ListStyle = fmListStyleOption
End With

frmPoolTypes.Show

End Sub

Private Sub cmdSave_Click()

Dim Choice As Long
Dim NewPool As String

Choice = lstPoolList.ListIndex

NewPool = txtNewPool

Range("PoolTypes").Item(Choice, 1).Value = NewPool

Unload frmPoolTypes

End Sub

Private Sub cmdCancel_Click()

Unload frmPoolTypes

End Sub

Do you see anything I've missed?

Thanks,

"Dave Peterson" wrote:

Any chance that you renamed that _initialize procedure to something like:
frmPoolTypes_Initialize
????

If you did, name it back to what excel expects it to be.
UserForm_Initialize

Karen53 wrote:

Hi,

Thanks to you both for your replies.

I have tried these:

With frmPoolTypes.lstPoolList
.RowSource =
Worksheets("Table").Range("PoolTypes").Address(ext ernal:=True)
and I tried
.RowSource = "PoolTypes"
and I tried
.RowSource = Sheets("Table").Range("PoolTypes")
End With

The form comes up but with no data. I get no error messages.

I have double checked the names of my form, listbox, sheet and range.

I can set the caption for the form ok, but I'm not getting the data range.

What else could I be missing?

Thanks

"Dave Peterson" wrote:

Try:
..RowSource = "PoolTypes"

Personally, I find this more self-documenting:
..RowSource = worksheets("sheet9999").Range("PoolTypes").address (external:=true)


Karen53 wrote:

Hi,

I have a listbox that I am trying to set the rowsource with VBA. If I set
the rowsource manually in the properties window to mynameedrange, my code
works great. I'm having trouble with the code setting it with VBA.

Here's what I have:

With frmPoolTypes.lstPoolList
.RowSource = Range("PoolTypes")
.BoundColumn = 1
.ColumnCount = 1
.ListStyle = fmListStyleOption
End With

What am I doing wrong?

Thanks,

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson