reply
I've tried two different ways in UserForm2_Initialization and neither one
worked :(
***********
** Try #1: **
***********
Public Sub UserForm2_Initialize()
ColCnt = ActiveSheet.UsedRange.Columns.Count
Set rng = ActiveSheet.UsedRange
Dim lr As Long
Dim r As Range
With ListBox1
.ColumnCount = ColCnt
.RowSource = rng.Address
cw = ""
For c = 1 To .ColumnCount
cw = cw & rng.Columns(c).Width & ";"
Next c
.ColumnWidths = cw
.ListIndex = 0
End With
lr = Sheets("FileNames").Cells(Rows.Count, "A").End(xlUp).Row
Set r = Range("A2:A" & lr)
Me.ListBox1.RowSource = "Filenames!" & r.Address
End Sub
***********
** Try #2: **
***********
Public Sub UserForm2_Initialize()
Dim rng As Range
Dim LastRow As Long
ThisWorkbook.Worksheets("Main").Activate
LastRow = Worksheets("Filenames").Range("A65536").End(xlUp). Row
With ThisWorkbook.Sheets("Filenames")
Set rng = .Range("A1:A" & LastRow)
End With
With ListBox1
For Each cell In rng.Cells
AddItem cell.Value
Next cell
End With
End Sub
--
Other programming languages I''''ve used a Cobol, C++, Informix Database,
and Unix.
"FSt1" wrote:
hi
accually that's userform2 initialazation code. listboxs and combobox don't
have an initialation evert. forms do.
try this....
Private Sub UserForm2_Initialize()
ColCnt = ActiveSheet.UsedRange.Columns.Count
Set Rng = ActiveSheet.UsedRange
dim lr as long
dim r as range
With ListBox1
.ColumnCount = ColCnt
.RowSource = Rng.Address
cw = ""
For c = 1 To .ColumnCount
cw = cw & Rng.Columns(c).Width & ";"
Next c
.ColumnWidths = cw
.ListIndex = 0
End With
lr = Sheets("FileNames").Cells(Rows.Count, "A").End(xlUp).Row
Set r = Range("A2:A" & lr)
Me.ComboBox1.rowsource = "Filenames!" & r.Address
End Sub
untested. watch for typos
regards
FSt1
|