Trouble defining Sub routine in XL10

Taylor714

New Member
Joined
Jan 29, 2013
Messages
4
Hello,

I'd appreciate any help on this as I'm going through the forums and don't appear to be finding an answer that works but I'll give you all the information I can and hopefully there may be a simple answer.

I'm getting the "Compile error: Sub of Function not defined" message and then points to the Search function as below.

FYI I'm using Office/Excel 2010 in Windows XP.

I've managed to get the Evaluate function to work (put in comments below) but I haven't been successful taking this forward as I need the macro to work with relative referencing (if I'm using the right term correctly) as I would like it to read other cells. By trying to put in a variable instead of the cell references didn't seem to work in the evaluate function. Therefore tried to develop another piece of code as below.

I've thought it might be a case that I haven't got the right References selected i.e. Tools>References and have the following 'ticked' but again still doesn't work:-

Visual Basic for Applications
Microsoft Excel 14.0 Object Library
OLE Automation
Microsoft Office 14.0 Object Library
Microsoft Office 14.0 Access database engine Object Library
Solver

The code I'm using at the moment is as below:-

Public Sub SecondAttempt()


Worksheets("Bill").Activate
Range("B5:F5").Select


If Count(Search(""" * masonry * """ & """ * bill * """, Range("b5:f5"))) = 2 Then
MsgBox "Match Found"
Else
MsgBox "No Match Found"
End If


'BELOW FORMULA WORKS BUT WITHOUT DYNAMIC RANGE
'If Evaluate("Sum(CountIf(B5:F5,{""*masonry*"",""*bill*""}))=2") Then
' MsgBox "Match Found"
'Else
' MsgBox "No Match Found"
'End If


End Sub

Again, appreciate any help on this as struggling to find what I would've thought was an easy fix..!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Just to update - may or may not be the right direction but I changed the code to below basically adding WorksheetFunction.Count and WorksheetFunction.Search

and now I get run-time error '13': type mismatch

still not sure what the solution is but thought I'd post it just in case its useful.



If WorksheetFunction.Count(WorksheetFunction.Search("""*masonry*""", Range("b5:f5").Cells)) > 0 Then
MsgBox "Match Found"
Else
MsgBox "No Match Found"
End If
 
Upvote 0
Evening,

To update progress.......... the following almost seems to work..... I've tried replacing the + signs with &'s but that doesn't work either. The formula works if I use > 0 but I need the formula to recognise a string of text rather than just one word:-

If WorksheetFunction.Sum(WorksheetFunction.Count(Range("B5:F5"), ("*masonry*" + "*support*" + "*system*"))) = 3 Then
MsgBox "Match Found you're epic"
Else
MsgBox "No Match Found"
End If

I've also tried CountIf but again that doesn't work.

so with a little finesse I'm hoping someone can fill in a little expertise here............?
 
Upvote 0
I get the impression I may be talking to myself here but if any one may have been looking at this - I think I've found the solution. so problem solved thank you very much.
 
Upvote 0

Forum statistics

Threads
1,216,526
Messages
6,131,187
Members
449,631
Latest member
mehboobahmad

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