Hi Folks,
I am using this code to place ainformation in a listbox.
In the properties window i have set the ColumnHeads to "TRUE" and so when the listbox opens the top line shows the lined boxes where the headers should go.
However when i use the code below to place the details in the listbox the headers appear in the second line below where they should be.
Can anyone tell me where i am going wrong please?
Thanks
I am using this code to place ainformation in a listbox.
In the properties window i have set the ColumnHeads to "TRUE" and so when the listbox opens the top line shows the lined boxes where the headers should go.
However when i use the code below to place the details in the listbox the headers appear in the second line below where they should be.
Can anyone tell me where i am going wrong please?
Thanks
Code:
Private Sub FindAllButton_Click()
Dim FirstAddress As String
Dim strFind As String 'what to find
Dim rSearch As Range 'range to search
Dim fndA, fndB, fndC, fndD, fndE, fndF, fndG, fndH, fndJ, fndK, fndL, fndM As String
Dim head1, head2, head3, head4, head5, head6, head7, head8, head9, head10, head11 As String
Dim I As Integer, intC As Integer
I = 1
Application.ScreenUpdating = False
'need to select archive page,screen updating off to hide this
Worksheets("Archive").Select
Set rSearch = Worksheets("Archive").Range("B7", Range("B65536").End(xlUp))
strFind = Me.TextBox5.Value
With rSearch
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then 'found it
'c.Select
head1 = Range("B6").Value
head2 = Range("C6").Value
head3 = Range("D6").Value
head4 = Range("E6").Value
head5 = Range("F6").Value
head6 = Range("G6").Value
head7 = Range("H6").Value
head8 = Range("J6").Value
head9 = Range("K6").Value
head10 = Range("L6").Value
head11 = Range("M6").Value
With Me.ListBox1
MyArray(0, 0) = head1 'Roy - changed this,ListBox must start from column 0
MyArray(0, 1) = head2
MyArray(0, 2) = head3
MyArray(0, 3) = head4
MyArray(0, 4) = head5
MyArray(0, 5) = head6
MyArray(0, 6) = head7
MyArray(0, 7) = head8
MyArray(0, 8) = head9
MyArray(0, 9) = head10
MyArray(0, 10) = head11
MyArray(0, 11) = head12
End With
FirstAddress = c.Address
Do
'Load details into Listbox
fndA = c.Value
fndB = c.Offset(0, 1).Value
fndC = c.Offset(0, 2).Value
fndD = c.Offset(0, 3).Value
fndE = c.Offset(0, 4).Value
fndF = c.Offset(0, 5).Value
fndG = c.Offset(0, 6).Value
fndH = c.Offset(0, 8).Value
fndJ = Format(c.Offset(0, 9).Value, "h:mm")
fndK = c.Offset(0, 10).Value
fndL = c.Offset(0, 11).Value
fndM = c.Offset(0, 12).Value
MyArray(I, 0) = fndA
MyArray(I, 1) = fndB
MyArray(I, 2) = fndC
MyArray(I, 3) = fndD
MyArray(I, 4) = fndE
MyArray(I, 5) = fndF
MyArray(I, 6) = fndG
MyArray(I, 7) = fndH
MyArray(I, 8) = fndJ
MyArray(I, 9) = fndK
MyArray(I, 10) = fndL
MyArray(I, 11) = fndM
I = I + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
End With
'Load data into LISTBOX
With Me.ListBox1
.List() = MyArray
End With
Worksheets("Main Sheet").Select
End Sub