I'm testing an Excel formula that returns Boolean (True or False)
This one works fine:
=OR(ISBLANK(B2),AND(LEN(B2)=12,ISNUMBER(SUMPRODUCT(FIND(MID(B2,ROW(INDIRECT("1:12")),1),"0123456789abcdefABCDEF")))))
Now I want to reverse the result. So I wrap a NOT() around it. But Excel won't take it. Why? Thanks!
=NOT(OR(ISBLANK(B2),AND(LEN(B2)=12,ISNUMBER(SUMPRODUCT(FIND(MID(B2,ROW(INDIRECT("1:12")),1),"0123456789abcdefABCDEF"))))))
To validate a MAC address (or find non-valid ones) split the address into 2 hexadecimals of 6 each and attempt a HEX2DEC conversion.
'validate
=OR(LEN(B2)=0, AND(LEN(B2)=12, IFERROR(HEX2DEC(LEFT(B2, 6))*HEX2DEC(RIGHT(B2, 6)), FALSE)))
=OR(LEN(B2)=0, AND(LEN(B2)=12, ISNUMBER(SUMPRODUCT(HEX2DEC(LEFT(B2, 6)), HEX2DEC(RIGHT(B2, 6))))))
'find non-valid
=NOT(OR(LEN(B2)=0, AND(LEN(B2)=12, IFERROR(HEX2DEC(LEFT(B2, 6))*HEX2DEC(RIGHT(B2, 6)), FALSE))))
=NOT(OR(LEN(B2)=0, AND(LEN(B2)=12, ISNUMBER(SUMPRODUCT(HEX2DEC(LEFT(B2, 6)), HEX2DEC(RIGHT(B2, 6)))))))
This is essentially what your original formula does but with less calculation load. tbh, I'm not sure why your NOT wrapper didn't work; it did for me.
Ive got the following statement in excel :
=IF(OR(L744=0, N744>0), "price ?", "")
I want to update it to be :
IF(OR(L744=0, N744>0), "price ?", "") ELSEIF(NOT(ISBLANK(P744), "")
But it seems excel dosnt have an ELSEIF block. Any ideas whats the most semantic way of writing this in excel ?
Use something like IF(condition, xx, IF(condition2, yy, zz)).
An IF in Excel is a function call, and hereby you are nesting the function calls.
Just guessing:
=IF(OR(A1=0,A2=0),"c",IF(NOT(ISBLANK(A3)),"a","b"))
I do not have this Excel version here. :)
I'm trying to use a formula in Excel to separate a bunch of words in a cell with a comma. If there are more than 5 words in the cell, I just want to get the first 5 words. To get the first five words in a cell and separate them by a comma I use this:
=SUBSTITUTE(LEFT(A1,FIND("^",SUBSTITUTE(A1," ","^",5))-1), " ", ", ")
This works fine. But the problem with this, because of the number 5 here, if I a cell contains less than 5 words, I get an error. I tried to substitute the 5 with this:
LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1
So my function becomes this:
=SUBSTITUTE(LEFT(A1,FIND("^",SUBSTITUTE(A1," ","^",LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1))-1), " ", ", ")
But this doesn't work, it gives me an error. Any idea how I can do this please?
Also I would like to ignore the first word if its first character is "-" (without the quotes) and just start from the second word. So in other words, I want something like this:
I love my life very much should return I, love, my, life, very
- I love my life very much should return I, love, my, life, very (the "-" is ignored")
I love my should return I, love, my
Thanks in advance for any help
Here's a somewhat different approach. Aside from the "less than 5" issue, it also deals with the "5 words with no space at the end" issue:
=LEFT(A1,FIND("^",SUBSTITUTE(A1 & "^"," ","^",5))-1)
EDIT 1: I just noticed the part about the leading "- ". My addition isn't very elegant, but it deals with it, and also TRIMS any trailing spaces:
=TRIM(LEFT(IF(LEFT(A1,2)="- ",MID(A1,3,999),A1),FIND("^",SUBSTITUTE(IF(LEFT(A1,2)="- ",MID(A1,3,999),A1) & "^"," ","^",5))-1))
EDIT 2: Oh yeah, commas:
=SUBSTITUTE(TRIM(LEFT(IF(LEFT(A1,2)="- ",MID(A1,3,999),A1),FIND("^",SUBSTITUTE(IF(LEFT(A1,2)="- ",MID(A1,3,999),A1) & "^"," ","^",5))-1))," ",",")
Try this:
=TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(A1,"-"," "))," ",","),",",REPT(" ",99),5),99))
This will work even if there is not a space after the dash or if there are extra spaces in the text. Often I find that input is not very clean.
=SUBSTITUTE(LEFT(SUBSTITUTE(TRIM(SUBSTITUTE(A1,"-","",1)),
" ","*",5),IFERROR(FIND("*",SUBSTITUTE(TRIM(SUBSTITUTE(A1,"-","",1)),
" ","*",5))-1,999))," ",",")
Edit: After commenting on István's, I made mine flawless too.
=SUBSTITUTE(LEFT(SUBSTITUTE(TRIM(SUBSTITUTE(LEFT(TRIM(A1),1),"-"," ",1)
&MID(TRIM(A1),2,999))," ","*",5),IFERROR(FIND("*",SUBSTITUTE(
TRIM(SUBSTITUTE(LEFT(TRIM(A1),1),"-","",1)&MID(TRIM(A1),2,999))," ","*",5))-1,999))," ",",")
But I think his is more elegant.
Try this:
=SUBSTITUTE(LEFT(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(A1,"- ","",1))&" "," ",", "),", ","|",MIN(LEN(SUBSTITUTE(TRIM(SUBSTITUTE(A1,"- ","",1))&" "," ",", "))-LEN(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(A1,"- ","",1))&" "," ",", ")," ","")),5)),FIND("|",SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(A1,"- ","",1))&" "," ",", "),", ","|",MIN(LEN(SUBSTITUTE(TRIM(SUBSTITUTE(A1,"- ","",1))&" "," ",", "))-LEN(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(A1,"- ","",1))&" "," ",", ")," ","")),5)))-1),",,",",")
The formula works by taking the following steps:
Remove any leading dash-space
Trim any leading or trailing spaces
Insert comma-spaces in place of spaces and add a trailing comma-space
Calculate the lesser of 5 and the number of words in the string
Put in "|" in place of either the fifth comma-space or the trailing comma-space if the string is less than five words
Determine the position of the "|"
Strip off the "|" and all characters to the right of it
Remove any doubled commas due to any single embedded commas in the initial string
If you are willing to consider a VBA solution, this complex expression can be replaced by a user-defined function:
Function words5(InputString As String) As String
Dim wordArray As Variant
wordArray = Split(Trim(Replace(InputString, _ 'remove "-", put words into array
"-", "", , 1)), " ")
ReDim Preserve wordArray(LBound(wordArray) To _ 'drop all but the first 5 words
WorksheetFunction.Min(UBound(wordArray), 5 - 1))
words5 = Replace(Join(wordArray, ", "), ",,", ",") 'rejoin the words with ", "
End Function 'separator
On the plus side of using this code is its maintainability compared to the worksheet formula, which impossible to understand or safely alter without access to the original building blocks that were combined into the single expression.
The code would have to be installed in the workbook in which it is used or in either the standard Personal.xlsb workbook or an addin workbook.
To use the function, copy and paste it into a standard module, which can be inserted into a workbook via the VBA editor. You can open the editor with the Visual Basic button on the `Developer tab of the ribbon.
Figured I'd throw my hat in the ring also. I think this formula should cover the bases:
=SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(TRIM(SUBSTITUTE(A1&" ","- ",""))," ",REPT(" ",99)),99*5))," ",",")
I have few cells where I fill date in those using 'FormatDatetime' function,
code:
Range("AX1") = FormatDateTime((Docx.getAttribute("r1ed")))
Range("AX2") = FormatDateTime((Docx.getAttribute("r2ed")))
Range("AX3") = FormatDateTime((Docx.getAttribute("r3ed")))
Range("AX4") = FormatDateTime((Docx.getAttribute("r4ed")))
If date is separated by "." all the cells would show like "12.1.2013",but if I change my system date format separated by "-","AX4" shows date as still "12.1.2013".but other shows correctly.
I need to have fix for this,since I use these dates' for calculation later in VBA.
Please suggest some answers.
I think your problem is that FormatDateTime() returns a string, change it to DateValue() instead. If the return from Docx.getAttribute() contains dots you'll need to replace them with slashes first.
So;
'[AX1] is the same as Range("AX1")
[AX1] = DateValue(Docx.getAttribute("r1ed"))
[AX2] = DateValue(Docx.getAttribute("r2ed"))
[AX3] = DateValue(Docx.getAttribute("r3ed"))
[AX4] = DateValue(Docx.getAttribute("r4ed"))
Or, if there are dots;
[AX1] = DateValue(Replace(Docx.getAttribute("r1ed"), ".", "/"))
[AX2] = DateValue(Replace(Docx.getAttribute("r2ed"), ".", "/"))
[AX3] = DateValue(Replace(Docx.getAttribute("r3ed"), ".", "/"))
[AX4] = DateValue(Replace(Docx.getAttribute("r4ed"), ".", "/"))
If this doesn't solve the issue, can you please post more info about what Docx.getAttribute() is returning please.
Edit: Also, knowing the format you need the cells to contain would be helpful - I'm assuming proper dates will be acceptable - You might need a string with a date in a certain format. If that's the case you could wrap the above with something like;
[AX1] = Format(DateValue(Docx.getAttribute("r1ed")), "dd/mm/yyyy")
It might be that FormatDateTime() is betraying you, Format() might be more flexible