VBA-Type Mismatch on .Find function.

JediJim

New Member
Joined
Jul 27, 2011
Messages
10
Guys,

I have a wall regarding my Macro. Bascially I have created functions, and the .find function which was previously working, now states type mismatch-specifically vOurResult code at the end is the problem

The whole code is this:


Function TextSearch()
'(ByVal strSearchFor, ByVal Target As Variant)

Sheets("MO Trade List").Select
Dim FoundCell As Range
Dim LastCell As Range
Dim FirstAddr As String
With Range("A2:A13")
Set LastCell = .Cells(.Cells.Count)
End With
Set FoundCell = Range("A2:A13").Find(What:="TCPAM Investments (Cayman) Limited - MENA Equity Fund", AFTER:=LastCell)
'Cells.FindNext(After.ActiveCell).Activate
'Cells.FindPrevious(After.ActiveCell).Activate

If Not FoundCell Is Nothing Then
FirstAddr = FoundCell
End If

Do Until FoundCell Is Nothing
FoundCell.Copy
Range("A20").Select
ActiveSheet.Paste
'If FoundCell. Found Then Do. FindNext(After:=FoundCell)
Set FoundCell = Range("A2:A13").FindNext(AFTER:=FoundCell)
FoundCell.Copy
Range("A21").Select
ActiveSheet.Paste
Set FoundCell = Range("A2:A13").FindNext(AFTER:=FoundCell)
FoundCell.Copy
Range("A22").Select
ActiveSheet.Paste
'Set FoundCell = Range("A2:A13").FindPrevious(After:=FoundCell)
If FoundCell = FirstAddr Then
Exit Do
End If
Loop









'If Not .Found Then Exit Do
'Loop Until Not .Found

End Function

'Fund Name
Function ValueCatching()
Sheets("MO Trade List").Select
Dim Fund1 As String

vOurResult = Cells.Find(What:="TCPAM Investments (Cayman) Limited - MENA Equity Fund", AFTER:=LastCell, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Offset(0, 3)


Please advise?

Thanks

JJ
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Is the problem in here?
Code:
Function ValueCatching()
Sheets("MO Trade List").Select
Dim Fund1 As String

vOurResult = Cells.Find(What:="TCPAM Investments (Cayman) Limited - MENA Equity Fund", AFTER:=LastCell, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Offset(0, 3)

You've told it to find after LastCell but no where prior to this is there a range object variable set to any specific range.
 
Upvote 0
Is the problem in here?
Code:
Function ValueCatching()
Sheets("MO Trade List").Select
Dim Fund1 As String
 
vOurResult = Cells.Find(What:="TCPAM Investments (Cayman) Limited - MENA Equity Fund", AFTER:=LastCell, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Offset(0, 3)

You've told it to find after LastCell but no where prior to this is there a range object variable set to any specific range.





Hi Jon-Thanks for the response, I actually just got it working again. I replaced LastCell with Cells (1, 1)-and for some reason this worked today buit didnt when I tried it previously.

Cheers anyway.

MOD can delete the thread

JJ
 
Upvote 0

Forum statistics

Threads
1,203,453
Messages
6,055,530
Members
444,794
Latest member
HSAL

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top