List Box in User Form filled by Range
I have a range of data on a worksheet and on the user form I have is a list
box, I want the user form to open and have the range of data added to the list box, how can this be done? The range will change when data is added... I have this code so far which opens the user form and shows me a blank list box, how can it be filled? Jez Option Explicit Dim adoRS As New ADODB.Recordset Sub addToList(rs As ADODB.Recordset, strShtName As String) Dim lngJ As Long For lngJ = 0 To rs.Fields.Count - 1 Sheets("AllActions").Cells(1, lngJ + 1) = rs.Fields(lngJ).Name Next Sheets("AllActions").Range("A2").CopyFromRecordset rs If rs.RecordCount = 1 Then If rs.RecordCount = 1 Then Me.lstActions.RowSource = "AllActions!A2:J" + CStr(findLastRow(Sheets("AllActions").Range("A2"), "") + 1) Me.lstActions.ColumnCount = rs.Fields.Count Me.lstActions.ColumnHeads = True Else Me.lstActions.RowSource = "AllActions!A2:J" + CStr(findLastRow(Sheets("AllActions").Range("A2"), "")) Me.lstActions.ColumnCount = rs.Fields.Count Me.lstActions.ColumnHeads = True End If Else Me.lstActions.RowSource = "AllActions!A2:J2" Me.lstActions.ColumnCount = rs.Fields.Count Me.lstActions.ColumnHeads = True End If Set adoRS = rs End Sub |
All times are GMT +1. The time now is 09:03 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com