Using the inch symbol as a condition in a if statement

David GCTW

New Member
Joined
Jun 11, 2018
Messages
1
Hi,

I'm trying to write a simple if statement to determine if a cell value is 12" or 14" but I'm getting an error because of the inch symbol. For example =if(A1 = "12"", 1,If(A1 = "14"",2,"-")). You can see the double quotes at the end of each search criteria in the formula, how do I tell excel to ignore the first "?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi & welcome to MrExcel.
How about
Excel Formula:
=IF(A1 = "12""", 1,IF(A1 = "14""",2,"-"))
 
Upvote 0
Fluff has given you the correct syntax for the way you were attempting to construct the formula. An alternate way of writing the formula is this...
Excel Formula:
=IF(A1 = 12&"""", 1,IF(A1 =14&"""",2,"-"))
The problem you ran into is that a (single) quote mark has a special meaning to Excel (and VBA as well)... it defines the start and end of a text constant... everything between them is to be taken as the characters they are with no special meaning (so if the letters LEN were inside a pair of quote marks, it would not be interpreted as the length function, just as three letters L, E and N). However, if you want to represent a quote mark character inside a text constant, you cannot use just a single quote mark for it because then Excel (and VBA as well) would not be able to tell if you are trying to end a text constant or if you meant that single quote mark to be just a single quote mark character. So, the syntax requires you to use two quote marks next to each other which Excel (and VBA as well) will interpret as a single quote mark character. So, in Fluff's formula, what I highlighted in red below (I also made them slightly bigger) represent a single quote mark and the black ones represent the beginning and end of text constants.

Rich (BB code):
=IF(A1 = "12""", 1,IF(A1 = "14""",2,"-"))

Using the same color scheme, here is how my formula would look...

Rich (BB code):
=IF(A1 = 12&"""", 1,IF(A1 =14&"""",2,"-"))[
 
Last edited:
Upvote 0
Here's another alternative.
Excel Formula:
=IF(A1=12&CHAR(34),1,IF(A1=14&CHAR(34),2,"-"))
If there are going to be more that 2 options in the final formula then there are likely going to be better methods to use, a lookup table in the sheet is most often the best one to use.
Although not really a practical method, an alternative formula following the same pattern as your example which serves the same purpose as 5 nested IF's.
Excel Formula:
=IFERROR(MATCH(A1,{12,14,16,18,20}&CHAR(34),0),"-")
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,317
Members
449,081
Latest member
tanurai

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