Nested Excel Functions in VBA

danbrawl93

New Member
Joined
Dec 15, 2016
Messages
17
Hello!

I am struggling to use the following nested function (written as if it was in a cell) in VBA:

=Iserror(Search("Hello",A1,1))

Essentially, I want the formula to produce FALSE if the cell contains the word "Hello" (there may be other words). This would be in a dynamic loop and the VBA I have tried is...

For n = z To y
If Evaluate("Iserror(search(""Hello"", cells(n,1), 1))") = True Then
Do stuff and end loop etc.


I have tried using WorksheetFunction but to no avail. I also cannot get the following to work, so I think the issue lies with how I am nesting the functions?

Range("A3").Value = Evaluate("sum(""I4:I6"",product(""K4:K6""))")

Please help, both with general syntax and the code highlighted in bold text!

Thanks :)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi welcome to the board!

For n = z To y
If Evaluate("Iserror(search(""Hello"", cells(n,1), 1))") = True Then
Do stuff and end loop etc.

Might be better to use the native VBA function for this, i.e.

Code:
For n = z To y
    If InStr(1, Cells(n, 1).Value, "hello", vbTextCompare) = 0 Then
        'Cell does not contain hello
    End If
Next n


Range("A3").Value = Evaluate("sum(""I4:I6"",product(""K4:K6""))")

For this you could try:

Code:
Range("A3").Value = Evaluate("sum(I4:I6,product(K4:K6))")
 
Last edited:
Upvote 0
If you insist on using Evaluate, try this:

Code:
If Evaluate("Iserror(Search(""Hello""," [COLOR=#ff0000]& Cells(n, 1).Address &[/COLOR] ", 1))") = True Then ...
 
Upvote 0
Sorry, I was a little confusing in my question - I meant to find the cell containing "Hello" (i.e. ISERROR would produce FALSE). Your solutions were both excellent though, thanks so much!! I will definitely be using this forum from now on. :):):):)
 
Upvote 0
... I meant to find the cell containing "Hello" (i.e. ISERROR would produce FALSE).
The Range.Find method works faster than checking cells one by one. Here is an example of using it:
Code:
Sub Test()
    Set c = [A1:A222].Find("Hello", [A222], xlValues, xlWhole)
    If Not c Is Nothing Then MsgBox c.Address
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

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