Dynamic listbox

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
78
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi,
How can I create a listbox in the userform?
that when I was in any sheet, it would show me the information of the same sheet.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You can use ActiveSheet reference to refer to the current active sheet. This example will populate items from A1 to A5, from the sheet which is currently selected.

VBA Code:
Private Sub UserForm_Initialize()
  ListBox1.List = ActiveSheet.Range("A1:A5").Value2
End Sub
 
Upvote 1
۰۰ can use ActiveSheet reference to refer to the current active sheet. This example will populate items from A1 to A5, from the sheet which is currently selected.

VBA Code:
Private Sub UserForm_Initialize()
  ListBox1.List = ActiveSheet.Range("A1:A5").Value2
End Sub
Thank you for your guide
My limits in each sheet are tables, should it be done in the same way for tables?
 
Upvote 0
Somehow you have to address your tables. For example this will select first table in actively selected sheets:
VBA Code:
Activesheet.listobjects(1)
 
Upvote 1
Somehow you have to address your tables. For example this will select first table in actively selected sheets:
VBA Code:
Activesheet.listobjects(1)
Hi
This code did not work for me
 
Upvote 0
Hello. See if the following is what you are looking for:

VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim k
k = Application.Match(Sh.Name, Array("Sheet1", "Sheet2"), 0)
If Not IsError(k) Then UserForm1.Show
End Sub

VBA Code:
Private Sub UserForm_Initialize()
  ListBox1.RowSource = ActiveSheet.ListObjects(1).Name
End Sub
 
Last edited:
Upvote 1
Solution
Hello. See if the following is what you are looking for:


VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim k
k = Application.Match(Sh.Name, Array("Sheet1", "Sheet2"), 0)
If Not IsError(k) Then UserForm1.Show
End Sub

VBA Code:
Private Sub UserForm_Initialize()
  ListBox1.RowSource = ActiveSheet.ListObjects(1).Name
End Sub
Hi,
Thank you for your beautiful answer
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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