Find/FindNext

PhilKib

New Member
Joined
Aug 16, 2015
Messages
17
Hello!
I hope someone can help me with this problem I'm having with some code I'm writing. I have a report that shows customer and various details about them, e.g. address, date they became a customer, payment details etc.
The task I have is to extract information contained in B2 and then to move the complete row to a new sheet called Rpt.
I did look at using a normal vlookup to pull this data however because the data in B2 can slightly change on a month by month basis (there is a formatting issues with customer input, for example an extra space or transposed digits) I think the best way would be to use the Find/FindNext.

So, the problem...
1) When the declared variable CustName is set as a String returns an error 'mismatch', however, when changed to a Variant, there is no error reported, but in the Watch window is does show as a 'String' has been applied to it
2) Once the above has been set as a Variant, I then get an error with the If statement 'runtime error 424, Object required. Please see below



Sub search()
Dim CustSearch As Range
Dim SearchRange As Range
Dim CustName As Variant
Dim wb As Workbook
Dim wsRpt As Worksheet

Set wb = ThisWorkbook
Set wsRpt = ThisWorkbook.Worksheets("Rpt")
CustName = InputBox("Type customer name")
Set SearchRange = Range("B6", Range("B5").End(xlDown))
Set CustSearch = SearchRange.Find(What:=CustName, MatchCase:=False, LookAt:=xlPart)

If CustName Is Nothing Then
MsgBox "No Customer found"
Else
wsRpt.Cells(1, CustName).Value
End If

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You are trying to use a string as a range,
Change this
VBA Code:
If CustName Is Nothing Then
To this
VBA Code:
If CustSearch Is Nothing Then

This will need some work also
VBA Code:
wsRpt.Cells(1, CustName).Value

But I am not sure where you are going with it, so I won't offer a mod for it.
 
Upvote 0
You are trying to use a string as a range,
Change this
VBA Code:
If CustName Is Nothing Then
To this
VBA Code:
If CustSearch Is Nothing Then

This will need some work also
VBA Code:
wsRpt.Cells(1, CustName).Value

But I am not sure where you are going with it, so I won't offer a mod for it.
[SOLVED] Thank you so much! I was stuck on this for ages until you kindly pointed me in the right direction, cheers again
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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