Dear reader,
I'm populating a Userform Listbox through a module that looks like this:
The code works fine but I have two problems with it:
1) The listbox shows just as many blanks as there are hits. I think this happens because the loop repeats the AddItem everytime. A solution would be to use a for-loop but that would slow the search down considerably. I need to go through 7000 rows, find the row number and return a value in column "A" and "C" that will be shown in the listbox. The FindNext is much faster but I need to combine it with a Do Loop.
2) I want the results to be shown in the opposite order (reversed). On top of the Listbox I want the last hit and then the second last hit and so on.
Maybe I should put everything in an Array first and then populate the Listbox from there but I have no idea how to do this.
Any thoughts ? All help is very welcome
Many thanks,
Jonerke
I'm populating a Userform Listbox through a module that looks like this:
Code:
Dim FindString As String
Dim LastRowStk As Integer
Dim Rng As Range
Dim Foundtwo As String
Dim FLRow As Integer
FindString = "Something"
LastRowStk = Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
Set Rng = Worksheets(1).Range("P1:P" & LastRowStk).Find(What:=FindString)
Foundtwo = Rng.Address
FLRow = Rng.Row
i = 0
Do
UserForm2.ListBox1.AddItem
UserForm2.ListBox1.List(i, 0) = Range("A" & FLRow).Value
UserForm2.ListBox1.List(i, 1) = Range("C" & FLRow).Value
Set Rng = Worksheets(1).Range("P1:P" & LastRowStk).FindNext(Rng)
FLRow = Rng.Row
i = i + 1
Loop While Rng.Address <> Foundtwo
The code works fine but I have two problems with it:
1) The listbox shows just as many blanks as there are hits. I think this happens because the loop repeats the AddItem everytime. A solution would be to use a for-loop but that would slow the search down considerably. I need to go through 7000 rows, find the row number and return a value in column "A" and "C" that will be shown in the listbox. The FindNext is much faster but I need to combine it with a Do Loop.
2) I want the results to be shown in the opposite order (reversed). On top of the Listbox I want the last hit and then the second last hit and so on.
Maybe I should put everything in an Array first and then populate the Listbox from there but I have no idea how to do this.
Any thoughts ? All help is very welcome
Many thanks,
Jonerke