Nested if issue

bfournier5

New Member
Joined
Apr 17, 2018
Messages
17
Hello, looking for some help to get this code working. The code I have working so far is to check if some specific text is part of a range or not. The saerch tells me if the text is French or English by searching for specific words. This part works and will place the value where the text is in a cell. Here is the code I have

' To see if the greeting is in English …
ActiveCell.Formula = "=MATCH(P1,SingleInteraction,0)"
ActiveCell.Offset(1, 0).Select
' To see if the greeting is in French …
ActiveCell.Formula = "=MATCH(P2,SingleInteraction,0)"
ActiveCell.Offset(-1, 0).Select


IsEnglish = ActiveCell.Value

GreetingRow = ActiveCell.Value

Range("S4").Select
ActiveCell.Offset(GreetingRow - 1, 0).Select
Selection.Copy

If the IsEnglish variable has a number - the code works. It means the result of ActiveCell.Formula = "=MATCH(P1,SingleInteraction,0)" is a value and then I get what I want.

If the result of ActiveCell.Formula = "=MATCH(P1,SingleInteraction,0)" is #n/a, then the code stop, which is normal because I want the code to go to take the value from ActiveCell.Formula = "=MATCH(P2,SingleInteraction,0)". Note that I'm in a If ... then ... Else with a loop.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Code:
If Not IsError("Match(P1, SingleInteraction, 0)") Then
This line is not doing what you want to do. You just pass a string to the IsError function. So, IsError always returns FALSE because there is no error. Try this:
Code:
If Not IsError(Application.Match(P1, SingleInteraction, 0)) Then
 
Upvote 0
Since I don't the worksheet, I tested the following code in A1:A20. The code does tell if the range contains English or French.

Code:
[COLOR=#008000]'To see if the greeting is in English … #n/a means it is not English[/COLOR]
If Not IsError(Application.Match(Range("P1"), Range("A1:A20"), 0)) Then
ActiveCell.Offset(1, 0).Select
ElseIf Not IsError(Application.Match(Range("P2"), Range("A1:A20"), 0)) Then
[COLOR=#008000]'To see if the greeting is in French … #n/a means it is not French[/COLOR]
ActiveCell.Offset(-1, 0).Select
Else
MsgBox ("no match")
End If

You said you got a type mismatch error on this line:

Code:
IsEnglish = ActiveCell.Value

What is in ActiveCell? IsEnglish is declared as an integer. If ActiveCell doesn't contain an integer, you'd get the error message.
 
Upvote 0
Since I don't the worksheet, I tested the following code in A1:A20. The code does tell if the range contains English or French.

Code:
[COLOR=#008000]'To see if the greeting is in English … #n/a means it is not English[/COLOR]
If Not IsError(Application.Match(Range("P1"), Range("A1:A20"), 0)) Then
ActiveCell.Offset(1, 0).Select
ElseIf Not IsError(Application.Match(Range("P2"), Range("A1:A20"), 0)) Then
[COLOR=#008000]'To see if the greeting is in French … #n/a means it is not French[/COLOR]
ActiveCell.Offset(-1, 0).Select
Else
MsgBox ("no match")
End If

You said you got a type mismatch error on this line:

Code:
IsEnglish = ActiveCell.Value

What is in ActiveCell? IsEnglish is declared as an integer. If ActiveCell doesn't contain an integer, you'd get the error message.

The ActiveCell as the value 5 in it.
IsEnglish is a declared variable like this ... Dim IsEnglish As Integer.

I can provide you with a sample Worksheet so that you see the issue.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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