Find position with the concurrence of a separator in Excel - excel

Good morning, I was looking for a formula to help me with this in Excel 2016, but I did not succeed, I have this text in a cell:
CF|0101|2019-02-05|01|F007-00000018|PEN|20539043782|6|20479636304|SERVICENTRO SANTA MARIA EIRL|CARRET. JAEN SAN IGNACIO KM 25- CAS. YANUYACU- JAEN||||||||6.10|33.90|6.10|0.00|0.00|0.00|0.00|0.00|0.00|0.00|0.00|0.00|0.00|0.00|33.90|40.00|0.00|0.00|40.00|1000|CUARENTA CON 00/100 SOLES |||||||M5K-788|
I want to extract the text with the help of the separator "|" and in a not so long formula, try with FIND, but the formula becomes very long after the third linked search, is there any way to obtain the position of the separator by number of concurrency? , something like this:
Searched text;Cell;Repetition number(concurrency of simbol)
=FORMULA("|";A1;2)
Result: 8
Or simulate something like this?
From already thank you very much.
**UPDATE
I will not use all the texts among the "|", that's why my need to obtain the position of the separators to extract only the text I need, since the tool "Text to Columns "forces you to give a position for all the separate texts.

If you truly want a formula that will separate everything into unique Columns. Then perhaps you should look at a custom formula. Here is a quick example of UDF that can parse data based on the "|"
Function SplitData(rng As String, Character As Variant, Position As Integer) As Variant
SplitData = Split(rng, Character)(Position - 1)
End Function
Once this function has been placed into a VBA module, then you can call this from any cell within that workbook.
To keep things simple here is the breakout...
=SplitData( <THE CELL THAT CONTAINS THE DATA YOU WISH TO PARSE>, <THE CHARACTER YOU WANT TO USE AS YOUR DELIMITER>, <POSITION IN WHICH YOU WANT TO DISPLAY THE TEXT (Valid Numbers start at 1+> )
The POSITION Point is used to display which section of the text. For example based on your example provided, if you populated the following...
=SplitData(A1, "|", 1) == "CF"
By the way, if you are dead set on finding the location of the "|", then how about using the =Search() formula. This will easily hunt do the character position of the first "|", but with a little bit of work you can get it to display other locations.

As outlined here, you can use Text to Columns:
Select the cell or column that contains the text you want to split.
Select Data > Text to Columns.
In the Convert Text to Columns Wizard, select Delimited > Next.
Select the Delimiters for your data. You'd want to put a | in the "Other" area.
Select Next.
Select the Column data format or use what Excel chose for you.
Select the Destination, which is where you want the split data to
appear on your worksheet.
Select Finish.
Or - if you literally just need all that in a single string, without |, you can use SUBSTITUTE():
=SUBSTITUTE(A1,"|"," ")

Related

how to separate text with multiple underscores and varying length of values

a1=ac_tree_birch_NewYork_ext
a2=bc_animal_dog_Washington_des
How do I separate the text in the cells by the "_", since there is varying length of the cell values. I would like to use a formula, and not text to columns.
Thanks
Use the SUBSTITUTE function to change all underscores (e.g. CHAR(95)) to a large number of spaces (typically the entire length of the original string) and peel out the padded pieces with the MID function. Finish off with TRIM and an IFERROR 'wrapper'.
In B1 as,
=IFERROR(TRIM(MID(SUBSTITUTE($A1, CHAR(95), REPT(CHAR(32), LEN($A1))), (COLUMN(A:A)-1)*LEN($A1)+1, LEN($A1))), TEXT(,))
Fill both right and down.
  
This can likely be done via Flash Fill (Excel 2013+).
For the first row of data, enter your expected outcome in subsequent cells to the right. This is how you want the data broken up:
Then select your first cell of output data and click Flash Fill from the ribbon:
Do this for the remaining columns. This will fill the column based on the pattern recognized by Excel within your original data:
If a VBA solution is acceptable, you can write a wrapper around the VBA Split function:
Public Function Split2(s As String) As String()
Split2 = Split(s, "_")
End Function
Then in your worksheet, select (say) cells B1:F1, enter
=Split2(A1)
as an array function (CTRL-SHIFT-ENTER), and out comes your data.
Hope that helps.

Formula to extract 10 or 11 digit phone numbers from random complex test string

I a newbee in field of excel formula and need your help in a complex formula, where i need to extract phone numbers from a string of random text. This does not have a fix format for the string
Example set off strings:
Dring to data add9724516002
add 08107936777 to me pler
8000069633 plz add. Me
9000088106 mujhe bhi add karo dosto
I have already tried many formulas but nothing seem to work. Only thing fixed is the length of number, it should be either 10 digits or 11 (including initial 0)
You could use a RegExp via VBA
(which seems to be coming to Excel as a formula option sometime down the track, see uservoice
code
Function GetCode(strIn As String) As String
Dim objRegex As Object
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
.Pattern = "\d{10,11}\b"
If .test(strIn) Then
GetCode = .Execute(strIn)(0)
Else
GetCode = "no match"
End If
End With
End Function
If they all look like the strings you have provided above, you could use Text to Columns. Let's say all of those strings were in A1:A4.
Select all four cells
Data - "Text to Columns"
Delimited
Use "space" to separate values
Finish
You will now have a large majority of your phone numbers pulled out, and it will look something like this:
(I've added a row above the data that makes every column its own set of data.. Column 1,2,3,4,5,and 6. I've also added another column in place of column A, Sort. This will be useful at a later stage)
Next, select A1:G5.
Click "Insert - Table"
"My table has headers"
OK
Your range is now a table, meaning you can sort the data via ascending order. I'm assuming you have hundreds of strings that you're sorting through. When you sort via ascending order, all numbers will show up first.
In the pic below I've sorted the first column of actual data, and there are two phone numbers at the top I can pull out:
If you ever want to revert back to your original lineup of data, click the Sort column to "Ascending"
I hope this is a good workaround to avoid VBA. You may not get all of the phone numbers, but probably a good chunk. You can also copy and paste columns C:G to the bottom of column A and sort everything at once if you only need all of the phone numbers.
If the strings that have numbers and letters attached are similar, you can also look into the RIGHT and LEFT formulas to pull out the numbers from the alphanumeric strings

Excel: Formula to extract a string of text delimited by markers from cells

I'm messing with a spreadsheet containing postal addresses that have been inserted in the cells' comments
Each comment contain an address composed of a variable number of lines (damn UK addresses, they can have up to 7 lines!) in the following format:
Line1,
Line2,
Line3,
[...],
State
With my poor skills, I've managed to extract the comment with a VBA script, obtaining the following string on a single cell:
Line1,Line2,Line3,[...],State
At this point each string between commas must be extracted to its own cell.
I've managed to extract the 1st 3 lines with the following formulas:
For Line1:
=LEFT(A8;(SEARCH(",";A8))-1)
For Line2:
=MID(A8; SEARCH(",";A8)+1; SEARCH(","; A8; SEARCH(","; A8)+1)-SEARCH(",";A8)-1)
For Line3:
=MID(A8; SEARCH(",";A8;SEARCH(",";A8;SEARCH(",";A8;SEARCH(",";A8)))+1)+1;SEARCH(","; A8; SEARCH(","; A8;SEARCH(",";A8)+1)+1)-SEARCH(",";A8;SEARCH(",";A8)+1)-1)
From this point I start to get overflow errors from my brain... I probably need some days of sleep.
Can anybody help me to get to "line6", and finally suggest me how to pull out the "State line" which ends without comma?
I thought I could pull out the "State" line with =RIGHT(",";SEARCH(",";A8)-1) but I'm obviously doing something wrong because that pulls out a comma instead of a string.
I guess I could do everything with a VBA script, but I'm not that skilled yet :(
With comma separated data in A1, in B1 enter:
=TRIM(MID(SUBSTITUTE($A1,",",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
and copy across. For example:
Note:
Why not use TextToColumns ?
The row of formulas re-calculates automatically if A1 changes.
The row of formulas will work even if A1, itself, contains a formula.
If you are wanting to do this programmatically instead of using a built-in, check out the split function for chopping up your comma separated string. It will split up your input string into an array. Then you can do whatever you like with the array.
Dim Names() As String
Names() = Split(inputValue, ",")
For i = 0 To UBound(Names)
' do what you want with each piece
Next
Gary's Student's answer is great for using the built-in functions.
If you want a VBA solution:
Sub spitString()
Dim sourceRange As Range
Dim stringArr() As String
Dim i As Integer
Set sourceRange = ActiveSheet.Range("A1")
stringArr = Split(sourceRange.Value, ",")
For i = LBound(stringArr) To UBound(stringArr)
sourceRange.Offset(0, i + 1).Value = stringArr(i)
Next i
End Sub
You could avoid adding comments: Are you aware that users can add line breaks inside a cell by pressing ALT+RETURN?
If having high rows d is a problem and you don't like that formatting, an alternative approach might be to write a simple bit of code that changes the height of the current row when a user clicks in a certain range. It would , make other rows less high. Perhaps.
Just a thought. It has benefits keeping it simple.
Harvey.

Excel formulas are not working - not recognizing numbers

I've pasted some numbers on Excel spreadsheet and wanted to do some calculations with it. The problem is that Excel isn't recognizing the numbers. I've already tried several methods to convert them into numbers and none of them works: paste/special multiplying by 1; formating each cell to the number/scientific number format. And there isn't also an error message on the top right corner of each cell like I've read on the internet indicating that there is a number written as text. If I retype each number, Excel recognizes it.
To make sure that the problem was really that the numbers were understood by Excel as text, I tried the functions ISNUMBER(), that returned FALSE and ISTEXT() that returned true.
I want to know how I can fix that problem without having to type into each cell.
Ps. the numbers are in scientific number format, i.e., 1,085859E+001 
Since the column is text the cells are formatted as text.
you use Value to convert the text into a number so the formula will work
A2 = 123
A3 = 123 Richard
Formula
=isnumber(A2) result is false
use
=isnumber(value(A2)) result is True
I was having the same problem, until I realized that the decimal separator was set as (,) instead of (.) in the default settings. Once I changed that, everything worked fine.
If your "numbers" are being detected as text, you can use VALUE() to make sure Excel understands that it is actually a number.
A1: `1.23E+10 (this is a string)
B1: =VALUE(A1)
=12300000000
C1: 1.23E+10 (this is a number)
D1: =IF(B1==C1,"It worked", "Uh Oh")
=It Worked (for me anyway)
I'm not sure what the comma in your scientific number will do so might want to have the function replace them if there not required.
See Kenneth Hobs' answer here: http://www.vbaexpress.com/forum/showthread.php?42119-Solved-Convert-exponential-format-to-a-number
Open your Excel File, Press Alt + f11 to open the VBA screen,
Go to Insert > Module, Copy and Paste Kenneth's code:
Sub Expo()
Dim cell As Range, s() As String, lng As Long, n As Integer
For Each cell In Selection
With cell
If Not VarType(.Value2) = vbString Then GoTo NextCell
s() = Split(cell.Value2, "E")
.Value2 = s(0) * 1 * (1 * 10 ^ s(1)) 'ePart(s(1))
.NumberFormat = "General"
.EntireColumn.AutoFit
End With
NextCell:
Next cell
End Sub
You can now run it as a macro to convert selected cells. Or if you want it as a function copy this code instead:
Function Expo(cell As Range)
Dim s() As String
With cell
If VarType(.Value2) = vbString Then
s() = Split(.Value2, "E")
Expo = s(0) * 1 * (1 * 10 ^ s(1)) 'ePart(s(1))
End If
End With
End Function
This way you can use it as a normal function in excel eg =Expo(A1)
As I mentioned in the comments above though, you will have already lost some degree of accuracy when the original number was converted to scientific notation. The best solution is to get the originating program to write the proper numbers into the text file if you can.
Open a new word document and try Pasting the web content in word first, the copy this content from the word document and paste special in excel, as text. This simple solution worked for me
Open a new blank Excel, then go to Data > From Text, this way you can import text and designate which format you want to convert to. On the Text Import Wizard page, select either Delimited or Fixed width (I am not sure how your original text file look like but generally it should be Delimited. On the next page, pick a Delimiter or enter one in Others. On step 3, you should see the data listed below and the data format on the upper left. Pick General for those columns that you believe should not be Text. This should fix your problem.
My case was stubborn, no response to Paste Special or CLEAN(). Finally resolved by copying the offending column of Excel data and pasting into new Notepad++ doc. This revealed a leading "?" in all the bad numbers (apparently some non-printing character). Used Search > Replace to find all "?" and replace with nothing. Edit > Select All, copy to a new Excel column, and voilà!
There may be hidden characters. Trailing/leading spaces may not visible and hence erroneously be neglected. If there is trailing/leading Space characters with numeric values, excel consider it as text.
Copy contents problematic cells to MS-Word [(Select problematic cells and copy them to MS-Word)] and check any hidden characters, Remove hidden characters with "find"/"replace" functionality.
I was having issues with numbers from PPT (e.g. ($3,000))pasted to excel. Tried multiple different ways to get the text to recognize including find replacing parens, commas, $ signs to blank and trying to format so excel could run formulas. The only option that worked was to paste to Word first then paste value to excel which worked without any additional formatting steps. Surprised I could not do it all within excel though. Maybe there's another way
Select all the cells to convert to a number.
|Data| Menu Tab > Data Tools > [Text to columns]
Delimited. [Next]
Deselect all "Delimiters". [Next]
"Column data format" > General
[Finish]
Verify by using =ISNUMBER(C16) in an spare cell, where C16 is a sample cell. Should now return TRUE.
This happened to me lately. I had forgotten that I had set formula recalculation to manual. The weird thing is that it was returing FALSE when initially created (which was correct) but given the test depended on the value of other cells that, when changed, did not trigger the change in the cell with the isnumber() formula.
Pressing F9 "fixed" my problem (and my ignorance).

Excel formula to remove space between words in a cell

I've a huge data in excel file.
For eg: say i've a word like paul son,i've to make it as paulson.
input:paul son
output:paulson.
In some cells ,i've data like mic-li,when this type of words come,it should not replace any thing,it should only remove spaces in between words.
Suppose the data is in the B column, write in the C column the formula:
=SUBSTITUTE(B1," ","")
Copy&Paste the formula in the whole C column.
edit: using commas or semicolons as parameters separator depends on your regional settings (I have to use the semicolons). This is weird I think. Thanks to #tocallaghan and #pablete for pointing this out.
It is SUBSTITUTE(B1," ",""), not REPLACE(xx;xx;xx).
Steps (1) Just Select your range, rows or column or array ,
(2) Press ctrl+H , (3 a) then in the find type a space
(3 b) in the replace do not enter anything,
(4)then just click on replace all.....
you are done.
Just wanted to add on to vulkanino's answer... now 10 years later ha. This is what I was looking for maybe someone else is too. You can also build on multiple =SUBSTITUTE() functions.
Here is what I used to format a list of names for Active Directory accounts. B2 is where the name would go. I wanted to change the space between the First name and last to a period and omit any hyphens from names.
=SUBSTITUTE(SUBSTITUTE(B2, " ", "."), "-", "")
For example the line above would look like this:
First Last-Name => First.LastName
, "-", "")
This part removes the hyphen.
(B2, " ", ".")
This part selects the cell to modify and changes empty space to a period.
=SUBSTITUTE(SUBSTITUTE(...)...)
I used two substitute functions one inside the other.

Resources