Listbox info using activesheet

JMSteyn

New Member
Joined
Mar 31, 2022
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Good day,

I have a workbook where I add members to a database (Sheet name: Data) through a user form and it contains its own list box. On this user forms list box the info is on a dedicated page so my code work.
Once a member is selected from this list box it opens a new user form and a new sheet named according to the members ID. On this user form there is another list box. This list box must now display information of the active sheet that was created after selecting the member on the first user form.
The problem is that I struggle to get the correct row source

Below is my code for the list box info.
--------------------------------------------------------------------------------
Sub Refresh_lstGear()

Dim sh As Worksheet
Set sh = ActiveSheet

Dim last_row As Long
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))

With Me.lstGear
.ColumnHeads = True
.ColumnCount = 4
.ColumnWidths = "50,100,200,100"

If last_row = 1 Then
.RowSource = ActiveSheet.Range("A7:D7")
Else
.RowSource = ActiveSheet.Range("A7:D") & last_row

End If
End With
End Sub
----------------------------------------------------------------------------------

Thanks in Advance
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,913
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Rowsource needs an address as text - eg "A7:D7"
 
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,167,159
Messages
5,852,434
Members
431,507
Latest member
gatobarbieri

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