Hello,
I am running Excel 2010 and Windows 7. I've been working on this for quite some time, and I am stumped. Any help is appreciated.
I have data on a hidden worksheet with three columns (A,B,C) and the number of rows varies but is typically a thousand or so. I paste data into this sheet from an excel report exported from another program.
I have a userform with a listbox. The listbox's row source is populated from the hidden worksheet mentioned above. I want to be able to multi-select rows in this listbox, click a button, and have the selected rows populated on another worksheet that is formatted.
I have some code that loops through the list box and populates arrays with the selected rows. I can populate the worksheet range with the data if the range is static ("A3:A6"). However, I need to make the range dynamic in that it should have the same number of rows as there are selected listbox rows. I have tried counting the number of selected rows with a variable and then setting the range's end row to that variable's value, but it doesn't work ("A3:A" & lUpper). It populates erratically.
If this doesn't make sense or you need more information, please ask.
The code is below.
I am running Excel 2010 and Windows 7. I've been working on this for quite some time, and I am stumped. Any help is appreciated.
I have data on a hidden worksheet with three columns (A,B,C) and the number of rows varies but is typically a thousand or so. I paste data into this sheet from an excel report exported from another program.
I have a userform with a listbox. The listbox's row source is populated from the hidden worksheet mentioned above. I want to be able to multi-select rows in this listbox, click a button, and have the selected rows populated on another worksheet that is formatted.
I have some code that loops through the list box and populates arrays with the selected rows. I can populate the worksheet range with the data if the range is static ("A3:A6"). However, I need to make the range dynamic in that it should have the same number of rows as there are selected listbox rows. I have tried counting the number of selected rows with a variable and then setting the range's end row to that variable's value, but it doesn't work ("A3:A" & lUpper). It populates erratically.
If this doesn't make sense or you need more information, please ask.
The code is below.
Code:
With FrmScheduler.LstWorkOrders
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''Loop through the listbox, If rows are selected, set 'lUpper' to count the rows'''''''''''
''''''''''''''''''''Set the contents of the array 'WOList' to the selected rows'''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For lLoop = 0 To .ListCount - 1
If .Selected(lLoop) Then
lUpper = lUpper + 1: ReDim Preserve WOListA(1 To lUpper), _
WOListB(1 To lUpper), WOListC(1 To lUpper)
WOListA(lUpper) = .List(lLoop, 0)
WOListB(lUpper) = .List(lLoop, 1)
WOListC(lUpper) = .List(lLoop, 2)
End If
Next lLoop
With Worksheets("Schedule")
'''Note: Stuck Here. Not sure why can't use variable in place of 6'''
.Range("A3:A" & lUpper) = Application.Transpose(WOListA)
.Range("B3:B6") = Application.Transpose(WOListB)
.Range("C3:C6") = Application.Transpose(WOListC)
End With
End With