list box not showing choices

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
163
I have a listbox that will show the range containing the choices, but only if the sheet with the range of choices is the active sheet. How to have the list box show the choices no matter what sheet is active. Below is my code for the userform. Form name is "samform". Listbox name is "sambox" The range containing the choices is "samlist"
VBA Code:
Sub show_samform()
samform.Show modal
With samform
    .Height = 300
    .Width = 280
    .Caption = "show_samform"
    With samform.Label1
        .Caption = "Enter"
        .Top = 2
        .Width = 200
        .Height = 30
        .Font.Size = 20
        .Font.Bold = True
        .ForeColor = vbBlue
        .Left = (samform.InsideWidth - .Width) / 2
        .TextAlign = fmTextAlignCenter
    End With
    With samform.Label2
        .Caption = Range("ReportName").Value
        .Top = 32
        .Width = 280
        .Height = 30
        .Font.Size = 20
        .Font.Bold = True
        .ForeColor = vbRed
        .Left = (samform.InsideWidth - .Width) / 2
        .TextAlign = fmTextAlignCenter
    End With
    With samform.Label3
        .Caption = "Samples"
        .Top = 62
        .Width = 200
        .Height = 30
        .Font.Size = 20
        .Font.Bold = True
        .ForeColor = vbBlue
        .Left = (samform.InsideWidth - .Width) / 2
        .TextAlign = fmTextAlignCenter
    End With
    With samform.sambox
        .Top = 102
        .Width = 100
        .Height = 120
        .Left = (samform.InsideWidth - .Width) / 2
        .RowSource = Range("samlist").Address
        .Font.Size = 10
        .Font.Bold = True
        .TextAlign = fmTextAlignCenter
        .MultiSelect = fmMultiSelectMulti
        .SetFocus
    End With
    With samform.samform_but
        .Top = 224
        .AutoSize = True
        .Caption = "OK"
        .Font.Size = 14
        .Font.Bold = True
        .ForeColor = vbBlack
        .Left = (samform.InsideWidth - .Width) / 2
    End With
End With
Do While samform.Visible
DoEvents
Loop
End Sub

Thanks for any help
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,448
Office Version
  1. 365
Platform
  1. Windows
What sheet is the list on?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,448
Office Version
  1. 365
Platform
  1. Windows
In that case try
VBA Code:
.RowSource = Sheets("Header").Range("samlist").Address(, , , 1)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,448
Office Version
  1. 365
Platform
  1. Windows
You're welcome
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,681
Messages
5,838,750
Members
430,567
Latest member
carid

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
Top