Error 2042, searching multiple worksheets

Closed
cjh28 - Nov 25, 2009 at 05:37 AM
 cjh28 - Nov 25, 2009 at 07:01 AM
Morning Guys,

Hope you can help me out a bit here,

I have workbook with 2 worksheets in it, using vlookup the first spreadsheet pulls information relating to elements in the first worksheet

Currently I have a userform I have created finds any instance of the user inputted search and tells you which sheet its in and allows u link to them. I also have a number of text boxes that I want populated with the information found on only the activesheet, not both. Currently I get a type mismatch error, and whilst it populates the information in debug mode I also get a Error 2042 on the following code:

TextBox5.Text = Cells(rngFind.Row, 2)

My full code looks like this:

[CODE]
Option Explicit

Sub locate(Name As String, Data As Range)

Dim rngFind As Range
Dim strFirstFind As String
Dim Find As String

With Data
Set rngFind = ActiveWorkbook.Sheets(1).Cells.Find(Name, LookIn:=xlValues, LookAt:=xlPart)
If Not rngFind Is Nothing Then
strFirstFind = rngFind.Address

Do
If rngFind.Row > 1 Then
ListBox1.AddItem rngFind.Value
ListBox1.List(ListBox1.ListCount - 1, 1) = Data.Parent.Name
ListBox1.List(ListBox1.ListCount - 1, 2) = Data.Parent.Name & "!" & rngFind.Address


'Find = rngFind.Cells
'Location

TextBox5.Text = Cells(rngFind.Row, 2)

'Speed
TextBox10.Text = Cells(rngFind.Row, 6)
'TextBox9.Text = Cells(rngFind.Row, 5)
'Suitability
TextBox7.Text = Cells(rngFind.Row, 4)
'IP Range
TextBox8.Text = Cells(rngFind.Row, 8)

End If
Set rngFind = .FindNext(rngFind)
Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstFind
End If
End With

End Sub

Private Sub CommandButton1_Click()

Dim shtSearch As Worksheet


ListBox1.Clear
For Each shtSearch In ThisWorkbook.Worksheets


locate TextBox1.Text, shtSearch.Range("A:M")

Next
If ListBox1.ListCount = 0 Then
ListBox1.AddItem "No Match Found"
ListBox1.List(0, 1) = ""
ListBox1.List(0, 2) = ""
'ListBox1.List(0, 3) = ""


End If
End Sub


Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

Dim strSheet As String
Dim strAddress As String

strSheet = ListBox1.List(ListBox1.ListIndex, 1)
strAddress = ListBox1.List(ListBox1.ListIndex, 2)

If strAddress <> "" Then
Worksheets(strSheet).Activate
Range(strAddress).Activate

End If
End Sub


Private Sub UserForm_Click()

End Sub
/CODE

Any help would be greatly appreciated

Thanks,
Chris
Related:

1 response

Ok I've now resolved the previous issue with this:

TextBox5.Text = Cells(rngFind.Row, 2).Text

but it now returns the incorrect information -- normally about 12 rows about the actual result.

However when I put a break point in (at any point within the textboxs or in the if statement after) and debug it, the values in the TextBox are correct

Any Ideas?

Tha
1