Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jez Jez is offline
external usenet poster
 
Posts: 38
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
list box on user form KJL Excel Programming 0 March 28th 07 02:02 AM
Searching in a user form / List box Idokras Excel Programming 2 November 25th 05 04:23 PM
How to: User Form to assign a user defined range to a macro variab TrevTrav Excel Programming 1 March 22nd 05 07:57 PM
User Form List Box Hank Hendrix Excel Programming 0 May 25th 04 10:22 AM
User Form / List Box Rockee052 Excel Programming 0 December 28th 03 04:55 AM


All times are GMT +1. The time now is 08:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"