I am using this formula in excel
=CHOOSE(RANDBETWEEN(1,6),”Item1″,“Item2”,“Item3”,“Item4”,“Item5”,“Item6”)
It's supposed to pick one of those values at random and return it in the cell, but I just get #NAME?.
What is the issue?
The #NAME? error signifies that something needs to be corrected in the syntax, so when you see the error in your formula, think of the syntax.
I don't see anything wrong with the syntax. But if you have copy-pasted the code into your Excel from a blogpost or somwhere else, maybe the double quotes characters are not the chars that Excel expect.
Try the following code instead, which has the standard double quotes.
=CHOOSE(RANDBETWEEN(1,6),"Item1","Item2","Item3","Item4","Item5","Item6")
Further info here
Whay does this happen? That comes from how computers work with characters (It's called ASCII). Maybe it's a very deep topic for the scope of this post. But, basically most programming languages accept only one type of character, while the platform (your Operating System) usually allows you a variety of representations for the same symbol (but different ASCII code), and that are thought for different contexts. In short, the double quotes look similar but the ASCII code are different:
" this char is accepted by Excel for enclosing values (open and close)
“ this char is not accepted by Excel for enclosing values (open)
” this char is not accepted by Excel for enclosing values (close)
For technical reference on this you can see this question
Related
In Excel VBA, I want to format some strings with 2 digits and others with 3 (only knowing at run-time which I want to use). This can be done using the format function, e.g., Format(number, "0.00") or Format(number, "0.000"). But the function ignores the argument between quotation marks when sent as a string argument. Does anybody know what variable type to use here for the argument and provide an example? Thanks so much, I tried everthing I can think of (double quotation marks etc.), but this specific problem is not covered on any website.
I'm trying to do a search for multiple strings in a cell with an OR-condition in Excel 2016.
E.g. I have a string abcd1234 and I want to find ab OR 12.
I'm using the german version where the function SEARCH is called SUCHEN and it should behave the same way.
I found this answer which suggests this solution:
SEARCH({"Gingrich","Obama","Romney"},C1).
I also found this website which suggests the same syntax:
SEARCH({"red","blue","green"},B5)
Same with this website:
SEARCH({"mt","msa","county","unemployment","|nsa|"},[#Tags])
So they basically say make a list of search terms separated by commas enclosed by curly braces and you're good.
But putting these into Excel 2016 just results in the usual meaningless Excel error message which says there was an error with the formula and it's always highlighting the whole part in curly braces.
Taking the first example the only way I could get Excel to not throw its error message was to change the syntax like this:
=SEARCH({"Gingrich";"Obama";"Romney"};C1)
But separating the search terms with semicolons doesn't apply the OR-condition correctly, so this is not the solution.
I'm aware from this answer that I could make separate searches and string them together with a condition, but I would like to avoid that, and I also want to know why the syntax that is supposed to work as confirmed by multiple sources is not working for me.
EDIT:
Okay, I'm starting to understand this, thanks to Solar Mike:
The code =IF(COUNT(SEARCH({"Romney","Obama","Gingrich"},A1)),1,"") works indeed perfectly fine.
Also =COUNT(SEARCH({"Romney","Obama","Gingrich"},A1)) works.
But =SEARCH({"Romney","Obama","Gingrich"},A1) does not.
Also =ISNUMBER(SEARCH({"Gingrich","Obama","Romney"},A1)) does not work.
I'd love to know the reason why.
Ok, so this works:
OR(IFERROR(FIND("ab",A1,1),0),IFERROR(FIND("12",A1,1),0))
tested here :
I followed one of the links and the version like this:
=IF(COUNT(SEARCH({"Romney","Obama","Gingrich"},C1)),1,"")
worked as expected for me, but if the search is isolated it then fails and I have not found an explanation ...
Like other array-style formulas, the part that delivers the array has to be enclosed in some sort of aggregate function to make it scan through the array - otherwise it only looks at the first element of the array. So anything like COUNT, SUM, SUMPRODUCT will do the trick.
My preferred one is
=OR(ISNUMBER(SEARCH({"a","b","c"},A1)))
because you can easily change it to this if you want AND logic:
=AND(ISNUMBER(SEARCH({"a","b","c"},A1)))
I regularly copy and paste values into an Excel spreadsheet and use the VALUE() function to convert them from text to numbers. However the following value is not getting converted and results in a #VALUE error:
−£13.24
I could do some complex string manipulation to remove the currency symbol, but just wondered if there was a simpler solution.
Any suggestions appreciated.
EDIT: I have just realised that it is not the currency symbol that is causing the problem, but the minus sign. I am copying the data from a website, and I guess it is using a different character encoding. Are there functions in Excel for handling character encoding?
I would use SUBSTITUTE to get rid of the currency character, e.g.
= SUBSTITUTE(D43,"£","")
And you could wrap the whole thing around a VALUE function, e.g.
= VALUE(SUBSTITUTE(D43,"£",""))
If you have issues with "long dash" vs. "short dash", (− vs. -), you can do this:
= VALUE(SUBSTITUTE(SUBSTITUTE(D43,"£",""),"−","-"))
Short dashes are required for Excel to recognize the string as a number.
=IF(LEFT(D43,2)="−£",-VALUE(MID(D43,3,LEN(D43)-2)),VALUE(D43))
This seems to do the job, but would be interested if there is a better/simpler solution.
I have written instruction from my college professor to type this formula:
=SIN(MOD($B5;23)/23*2*PI()),
but when I do it, Excel won't accept it, because the formula contains an error.
Am I doing something wrong or is it possible that professor gave us bad instructions?
If the formula contains , character too, then that's why. Otherwise the formula works for me in a blank Excel, which means that the error may be somewhere in $B5 if it's not the , character.
functions:
sin()
mod()
pi()
and parenthesis seems ok + the rest is just numbers. (Excel 2010)
=SIN(MOD($B5;23)/23*2*PI())
It looks like your professor made a typo on the instructions. Try
=SIN(MOD($B5,23)/23*2*PI())
I'm not on a computer with Excel so I'm unable to test it. However, the documentation for the MOD function in excel uses a comma instead of a semicolon.
Thanks, professor made a typo, it's working when I put comma instead of the semicolon.
I'm building a VBA program on Excel 2007 inputing long string of numbers (UPC). Now, the program usually works fine, but sometimes the number string seems to be converted to scientific notation and I want to avoid this, since I then VLook them up.
So, I'd like to treat a textbox input as an exact string. No scientific notation, no number interpretation.
On a related side, this one really gets weird. I have two exact UPC : both yield the same value (as far as I or any text editor can tell), yet one of the value gives a successful Vlookup, the other does not.
Anybody has suggestions on this one? Thanks for your time.
Long strings that look like numbers can be a pain in Excel. If you're not doing any math on the "number", it should really be treated as text. As you've discovered, when you want to force Excel to treat something as a string, precede it with an apostrophe.
There are a couple of common problems with VLOOKUP. The one you found, extra whitespace, can be avoided by using a formula such as
=VLOOKUP(TRIM(A1),B1:C:100,2,FALSE)
The TRIM function will remove those extraneous spaces. The other common problem with VLOOKUP is that one argument is a string and the other is a number. I run into this one a lot with imported data. You can use the TEXT function to do the VLOOKUP without having to change the raw data
=VLOOKUP(TEXT(A1,"00000"),B1:C100,2,FALSE)
will convert A1 to a five digit string before it tries to look it up in column B. And, of course, if your data is a real mess, you may need
=VLOOKUP(TEXT(TRIM(A1),"00000"),B1:C100,2,FALSE)