Hi guys
im using an adapted version of Roys database. Heres my code:
Code
Private Sub cmbFindcode_Click()
Application.ScreenUpdating = False
Sheet3.Activate
Dim strFind, FirstAddress As String 'what to find
Dim rSearch As Range 'range to search
Set rSearch = Sheet3.Range("b8", Range("b65536").End(xlUp))
strFind = Me.TextBox2.Value 'what to look for
Dim f As Integer
If Me.TextBox2.Value = "" Then
MsgBox "Please enter a Fund code to search for"
GoTo nullentered
End If
With rSearch
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then 'found it
c.Select
With Me 'load entry to form
.TextBox1.Value = c.Offset(0, -1).Value
.TextBox2.Value = c
.TextBox3.Value = c.Offset(0, 1).Value
f = 0
End With
FirstAddress = c.Address
Do
f = f + 1 'count number of matching records
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
If f > 1 Then
If f > 50 Then
MsgBox "There are more than 50 funds with """ & strFind & """ as part of the code. Please narrow your search criteria"
Call CommandButton2_Click
Else
MsgBox "There are " & f & " funds with " & strFind & " as part of the code"
Me.Height = 489
End If
Me.cmbFind.Enabled = False
Me.cmbFindcode.Enabled = False
End If
Else: MsgBox strFind & " not listed" 'search failed
Me.cmbFind.Enabled = True
Me.cmbFindcode.Enabled = True
End If
End With
Call cmbFindcodeAll_Click
nullentered:
Sheet2.Activate
End Sub
Private Sub cmbFindcodeAll_Click()
Dim FirstAddress As String
Dim strFind As String 'what to find
Dim rSearch As Range 'range to search
Dim fndA, fndB, fndC As String
Dim head1, head2, head3 As String 'heading s for list
Dim i As Integer
i = 1
Set rSearch = Sheet3.Range("b8", Range("b65536").End(xlUp))
strFind = Me.TextBox2.Value
With rSearch
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then 'found it
c.Select
'load the headings
head1 = Range("a7").Value
head2 = Range("b7").Value
head3 = Range("c7").Value
With Me.ListBox1
MyArray(0, 0) = head1
MyArray(0, 1) = head2
MyArray(0, 2) = head3
End With
FirstAddress = c.Address
Do
'Load details into Listbox
fndA = c.Offset(0, -1).Value
fndB = c.Value
fndC = c.Offset(0, 1).Value
MyArray(i, 0) = fndA
MyArray(i, 1) = fndB
MyArray(i, 2) = fndC
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
Me.ListBox1.List() = MyArray
Sheet2.Activate
End Sub
Display More
This works fine for the first part - i.e it loads the data into the textboxes, and loads the headers and first search result into the listbox. However it always only loads the first search result, not all.
Does anyone know why this might be? If its not clear I can post a simplified example of the working spreadsheet.
Thanks in advance[hr]*[/hr] Auto Merged Post;[dl]*[/dl]Ive uploaded an example to assist anyone kind enough to assis me
Thanks