Userform - Listbox - not populating table properly

Kawule

New Member
Joined
Nov 21, 2016
Messages
23
So I've been working on my userform and today I added in a new page to my multipage and encountered a new problem after implementation.

What I've found is that 75% of the time the Listbox's rowsource has no value and 25% of the time it seems to keep the value. The data it pulls from is on a hidden sheet named "Operators" with a named range called "OprTbl"
Here is the snippet of the code I placed in the UserForm_Initialize section:
Code:
Private Sub UserForm_Initialize()
MultiPage1.Value = 0
'Populate the Approval page
Dim ws As Worksheet
Dim ws2 As Worksheet
Set ws = Worksheets("Operators")
Set ws2 = Worksheets("Approval")
'This populates the listbox with the operator table
With Me.OperatorsListBox
    .RowSource = ws.Range("OprTbl").Address
End With
'Sets all the label captions from the approval table
Me.AprLbl.Caption = ws2.Range("a2")
Me.AppLbl.Caption = ws2.Range("b2")
Me.EffDateLbl.Caption = ws2.Range("c2")
Me.ExpDateLbl.Caption = ws2.Range("d2")
Me.AprHdrLbl.Caption = ws2.Range("e2")
End Sub

When I was debugging it I noticed that after the End With .RowSource becomes empty instead of being assigned the named range that I setup.
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Why not just set RowSource to 'OprTbl'?
 
Upvote 0
Do you mean just putting in
Code:
Me.OperatorsListBox.RowSource = Range("OprTbl").Address
Instead of having it inside the With statement? I tested with the Me.OperatorsListBox.RowSource = Range("OprTbl").Address only and still running into the same issue the list box won't populate
 
Upvote 0
No, all you should need is this.
Code:
Me.OperatorsListBox.RowSource = "OprTbl"
 
Upvote 0
Well that worked thanks! I dunno why it originally worked when I used the "With" statement and then it broke immediately after that but your solution is a lot simpler.
 
Upvote 0
In the first code you posted the sheet reference would have been missing.
 
Upvote 0

Forum statistics

Threads
1,216,137
Messages
6,129,093
Members
449,486
Latest member
malcolmlyle

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