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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Rowsource needs an address as text - eg "A7:D7"
 
Upvote 0

Forum statistics

Threads
1,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

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