I have spreadsheet, that contains a string of numbers (text) I need to extract the text within the parentheses and count how many meet the critera
I tried the follow code:
=COUNTIF(NASC!C:C,"MID(NASC!C:C,SEARCH(zv489408,NASC!C:C,22))")
But it is not returning a value.
here is the string that it must search from:
1234595250110784533 (zv489408)
and its on separate sheet that labelled NASC
Disclaimer: I work in Ubuntu and these have been tested in LibreOffice, not Excel. There may be some discrepancies between the programs.
Your core function should be SEARCH("(zv489408)", NASC!C:C). (The 22 in your example starts searching from the 22nd character in the cell; this will not find the string if it occurs earlier in the cell.) That will return the starting character of the string in that cell, or an error (probably #VALUE!).
You could set up another column, with the formula =NOT(ISERROR(SEARCH("(zv489408)", NASC!$C1))) in each cell (the 1 will change to the row relevant to each cell, of course), and then SUM that column up in another cell.
I have managed to find an array formula that works, but I'm warning you now, it's nasty:
=COUNTIF(MID(NASC!C:C, SEARCH("(", NASC!C:C) + 1, SEARCH(")", NASC!C:C, SEARCH("(", NASC!C:C)) - SEARCH("(", NASC!C:C) - 1), "zv489408")
(Hit Ctrl+Shift+Enter to save a formula as an array formula.)
It's nasty because it goes through all of these steps, and can't save the intermediate results:
Find the opening bracket.
Find the closing bracket after the opening bracket.
Subtract the position of the opening bracket from the position of the closing bracket to get the length (plus one more, to exclude the closing bracket).
Get the text between them.
Related
This is the problem i am facing in Excel formula
enter image description here
In column F, i want to find the common text across A2 to E2 (containing Blanks)
My Question:
Is there a simple way to get the result without VB?
Any help is appreciated,thanks
I found that google sheets has some really cool functions.
If you put the formula =SPLIT(A1, ",", TRUE,FALSE) in the cell after your row of common text (or probably even in a different sheet - "probably because hadn't tried it, though it should), the next x cells (where x is the number of "," in A1 - because "," is the delimitator) will be the text.
then you can put the code =IF(SUM(ARRAYFORMULA(if(REGEXMATCH($A$1:$D$1,F1),1,0)))=COUNTA($A$1:$D$1),F1,"") into an equal number of cells after that (probably should just put into the max number), and =CONCATENATE(I1:L1) into the last cell.
Ok. So to tweak this for yourself: I found that ARRAYFORMULA lets you put an array in place of a single cell in a function inside. how it exactly works I read its like a for loop. but I can't really vouch for that. but here it lets you have REGEXMATCH (which is a Boolean check on the cell you give it for if it contains the given REGEX) check each cell in the array.
the sum will add them up, and the if will match against the COUNTA to find if the number of cells in the array that contain this string is equal to the number of non-empty cells.
the concatenate at the end adds all the cells (containing the regex function) together, and since the only non-empty cells will be the one with the string, that is what this cell will return (no spaces).
code:
results:
the test data:
If you need in specifically Excel... this won't help.
We can use power query to achieve the desired result.
Unpivot the columns in Power query
Split all the columns by Comma delimiter
Create a custom column to see if the first column records exist in the remaining columns.
Use the functionText.contains.
Sample function: =Text.Contains([column.1],[column.1]&[column.2]&[column.3])
If the above function returns TRUE then get the first column result(This is the expected result) and load the data back to your excel
I need to find the starting cell number and the ending cell number of a specific value. For example if I have this excel sheet:
Here, I when I search for “10:” in the formula, I should get:
A1:A5
For example there’s this formula =COUNTIF(range, text) using this formula I can count the number of times that certain text is being repeated. Now I need a formula where when I enter a text, it should tell me the starting cell number and the ending cell number.
I hope I’m clear. Is this possible?
You need =iferror("A"&MATCH("10*",A:A,0) & ":A"&MATCH("10*",A:A),"") if you were searching for things that begin with 10. You can change 10 to a cell reference so long as you & "*" onto that.
The first MATCH piece gives the first matching row number in the range (which since I am looking at the whole column is the row number) and the second gives the last that is <= (in our case = because we found a first that is =). If we find nothing, the iferror handles that and returns blank for the whole thing.
The above is assuming column A is formatted as text (and sorted -- it is not meant to handle if the matching entries were in a1:a3 and then there was another in A7).
Given a spreadsheet cell containing a string that consists of a hyphenated series of character segments, I need to extract the last segment.
For example, consider column A containing data strings like XX-XXX-X-XX-XX-G10, where X denotes any character. What formula would I need to place in column B to get G10 as a result?
A B
1 XX-XXX-X-XX-XX-G10 G10
I'm looking for a formula that could work in in Libre Office Calc, Open Office Calc, MS Excel, or Google Sheets.
Another possibility in LO Calc is to use the general purpose regular expression macro shown here: https://superuser.com/a/1072196/541756. Then the cell formula would be similar to JPV's answer:
=REFIND(A1,"([^-]+$)")
If you are using google sheets, regexextract would be possible too:
=REGEXEXTRACT(A1, "[^-]+$")
In LibreOffice Calc and OpenOffice Calc, you can use a regular expression to determine the position of the text after the last - character:
=SEARCH("-[:alnum:]+$";A1)
will return 15 if A1 contains XX-XXX-X-XX-XX-G10.
Now, you can use this value to get the text "behind" that position, using the RIGHT() function:
=RIGHT(A1;LEN(A1)-SEARCH("-[:alnum:]+$";A1))
Split up on multiple lines:
=RIGHT( ' return text beginning from the right...
A1; ' of cell A1 ...
LEN(A1) ' start at lenght(A1) = 18
- ' minus ...
SEARCH( ' position ...
"-[:alnum:]+$" ' of last "-" ...
;A1 ' in cell A1 = 15 ==> last three characters
)
)
It appears that you want the characters that appear at the end of a string, to the right of the last instance of a hyphen character, "-".
This formula, adapted from here, works in Excel, *Calc & Google Sheets:
=TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",LEN(A1))),LEN(A1)))
Explanation:
SUBSTITUTE(A1,"-",new_string) will find each hyphen ("-") in the original string from cell A1 and replace it with a new_string.
REPT(" ",LEN(A1)) is a string of repeated space characters (" "), the same length as the original string in cell A1.
TRIM(RIGHT(string,count)) will get the right-most count characters, and trim off leading and trailing spaces. Since the string was previously padded out by replacing hyphens with spaces, and count is the same LEN(A1) used for that padding, the last count characters consists of a bunch of spaces followed by whatever followed the last hyphen!
In Google Sheets, an alternative approach is to use the SPLIT function to break the value from column A into an array, then select the last element. (Excel-VBA has a split() function, so you could make this work in Excel by writing VBA code to provide it as a custom function.)
=INDEX(SPLIT(A1,"-"),0,COUNTA(SPLIT(A1,"-")))
I found simply solution:
=RIGHT(A1;3)
that gives me G10 as the result too! It works because COL A always have 3 chars at the end!
A program that exports to Excel creates a file with an indented list in a single column like this:
Column A
First Text
Second Text
Third Text
Fourth Text
Fifth Text
How can I create a function in excel that counts the number of white spaces before the string of text?
So as to return: 1 for the first text row and 3 for the for the thirst row, etc in this example.
Preferably seeking a non-VBA solution.
TRIM doesn't help here because it removes double spaces also between words.
The main idea is to find the FIRST letter in the trimmed string and find its position in the original string:
=FIND(LEFT(TRIM(A1),1),A1)-1
You can try this function in Ms Excel itself:
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))
This would apply if the results are in a single cell. If it is for a whole row/column, just drag the formula accordingly.
Try below:
=FIND(" ",A1,1)-1
It calculates the position of the first found whitespace character in a cell and reduces it by 1 to reflect number of characters before that position.
As per http://www.mrexcel.com/forum/excel-questions/61485-counting-spaces.html, you may try:
=LEN(Cell)-LEN(SUBSTITUTE(Cell," ",""))
where Cell is your target cell (i.e. A1, B1, D3, etc.).
My example:
B8: =LEN(F8)-LEN(SUBSTITUTE(F8," ",""))
F8: [ this is a test ]
produces 4 in B8.
The above method will count spaces before the string if any were inserted, between individual words and after the string, if any were inserted. It won't count available space that does not have an actual white space character. So, if I inserted two spaces after test in the above example, the total count would be raised to 6.
As has been pointed out in the other answers, you can't really use TRIM or SUBSTITUTE as potential spaces in between words or at the end will give you the wrong result.
However, this formula will work:
=MATCH(TRUE,MID(A1,COLUMN($A$1:$J$1),1)<>" ",0)-1
You need to enter it as an array formula, i.e. press Ctrl-Shift-Enter instead of Enter.
In case you expect more than 10 spaces, replace the $J with a column letter further down in the alphabet!
Here's my solution. If the left 5 characters equals "_____" (5 blank spaces), then return 5, else look for 4 spaces, and so on.
=IF(LEFT(B1,5)=" ",5,IF(LEFT(B1,4)=" ",4,IF(LEFT(B1,3)=" ",3,IF(LEFT(B1,2)=" ",2,1))))
You almost got it with LEN + TRIM in answers before, you only need to combine both:
=LEN(Cell)-LEN(TRIM(Cell))
If it is Indented you could create a Personal Function like this:
Function IndentLevel(Cell As Range)
'This function returns the indentation of a cell content
Application.Volatile
'With "Application.Volatile" you can make sure, that the function will be
recalculated once the worksheet is recalculated
'for example, when you press F9 (Windows) or press enter in a cell
IndentLevel = Cell.IndentLevel
'Return the IndentLevel
End Function
This will work only if it is Indented, you can see this property in the Cell Format -> Alignment.
After This you could see the Indentation Level.
I have variating numeric entries (SF123456, SF142365, ...). Every number of the numeric entries corresponds to a specific code. For each number of each entry I need to enter on a separate cell the corresponding code (download here example sheet: www.nivpat.com/Example.zip) How can I create an automatic function as I have thousands of entries to divide into codes... thanks!
Alright. What I did to solve this one is this:
Remove the '=' sign in your match table to be able to do a VLOOKUP on it;
Add the position of the digit you want to look up in the row 9 right above the headings. You might want to hide this row for cleaner presentation;
I used the following formula in the cells to extract the values:
=VLOOKUP(VALUE(MID($A11, B$9, 1)), $A$2:$B$7, 2, 0)
The VLOOKUP does the lookup on your table in A2:B7. The MID() extract exactly one character beginning with the character specified in B9 (in this case it would be 3). And the VALUE() converts the text string to a number to be able to do a match with the table above.
The only thing you now have to do is to drag your formulas and it's working !