View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Wendy Wendy is offline
external usenet poster
 
Posts: 35
Default Listbox rowsource on Userform

Hi

I can only get Dave's solution to populate the form if the worksheet "data"
is in the same workbook as the form and post.xls is actually in
D:\Temp\Post.xls

Wendy


"Dave Peterson" wrote in message
...
I'd use:

Option Explicit 'forces you to declare your variables
Private Sub UserForm_Initialize()

Dim myRng As Range
Dim LastRow As Long

'With Workbooks("post.xls").Worksheets("data")
'or if the data was in the same workbook as the userform
'With ThisWorkbook.Worksheets("data")
'I didn't include the extra blank row!
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set myRng = .Range("A2:C" & LastRow)
End With

With Me.ListBox1
.RowSource = myRng.Address(external:=True)
.ColumnCount = myRng.Columns.Count
End With

End Sub




Wendy wrote:

Hi

I'm trying to set the rowsource of a listbox, I keep getting subscript
out
of range error.

Thanks

Wendy

Private Sub UserForm_Initialize()
Dim LastRowNo As Long
Dim LastRow as String
Set ws = Workbooks("post.xls").Worksheets("data")

'find first empty row in sheet

LastRowNo = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
LastRow = "A2:C" & LastRowNo

Me.ListBox1.RowSource = LastRow

End Sub


--

Dave Peterson