Is there a function that I can use to remove the first few characters from a cell?
Example
1 some text
23 some more text
I need to remove the numbers so that the cells read
some text
some more text
You can use LEFT, RIGHT and MID functions to slice bits of Text out of a cell, and LEN to find the number of characters in a cell. The FIND function will return the position of a specified bit of text within a cell. And you can use the & operator to join text together
So If A1 holds "some text 23 some more text" then the following formula in B1
=LEFT(A1,10)&RIGHT(A1,14)
would return "some text some more text"
If the numbers are randomly interspersed within the text however, then you will have to resort to VBA to remove them
If you only need to remove numbers (as in all numbers) from a cell you can also repeatedly use SUBSTITUTE
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,0,""),1,""),2,""),3,""),4,""),5,""),6,""),7,""),8,""),9,"")
Though it would leave behind double spaces " " in the end so you might want substitue those double spaces with single spaces. In the following it replaces it 5 times (assuming the text would be something like some text 23 01 52 63 some more text
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,0,""),1,""),2,""),3,""),4,""),5,""),6,""),7,""),8,""),9,"")," "," ")," "," ")," "," ")," "," ")," "," ")
Related
I have a list that looks something like this
What I want to do is create a formula so in another cell I get the following
'ID1','ID2',ID3','ID4'
It doesn't matter if at the very beginning and at the very end I get extra characters because I can remove those manually, my issue is that in reality this list has hundred of IDs and I can't do this manually.
In next column (assuming data starting in A1):
in B1 = " ' " & A1 & " ' " and drag down (I added spaces to make readable, but you don't want them within the quotes in your actual formuale)
Then in C1 = B1, and in C2 = C1&","&B2, and drag down.
I have a formula that looks at Cell A1 on a worksheet called "FolderDataImport" (copied down the whole column).
=MID(LEFT(FolderDataImport!A1,FIND("(",FolderDataImport!A1)-1),FIND("- ",FolderDataImport!A1)+2,LEN(FolderDataImport!A1))
It selects and returns any data/text after the character "-" and before the character "(".
This works perfectly for example text 1 below and it would return "An Example Text"
Example Text 1
"This Is - An Example Text (Sometimes formatted) [Like This] (Which I Will) Call Example 1"
but some times the data it is looking at is formatted as shown in example text 2 where the is no text enclosed in left and right Parenthesis BEFORE the character "[" meaning it returns everything between the "-" and the ( like "Another Example [But Is Different]"
Example Text 2
"This Is - Another Example [But Is Different] (Which I Will) Call Example 2"
There may be a better way of doing this but what I need the formula to do is starting from the first character on the left find the "-" and then IF it finds a "(" return the characters
(as in my example text 1) "An Example Text" BUT if it finds a "[" before it finds a "(" (as shown in text example 2, then it only returns the text between "-" and "[" which, using my text example 2, would be "Another Example".
This added complication is beyond my somewhat lacking skills?
You could try the following:
Formula in B1:
=MID(A1,FIND("-",A1)+2,MIN(FIND({"[","("},A1))-FIND("-",A1)-3)
I guess without Microsoft365 it would be an CSE-entered formula.
The problem I am having here or hope to understand is that the characters in a cell seem to change from a programmatic perspective between macro produced values then double clicking the cell (probably explaining this horribly). To explain further, I have a macro that pulls variable paragraph sized strings and puts them in each cell within a given range. The next thing I try do is to use another macro on the newly produced range to remove extra newlines (2+ consecutive newlines). For whatever reason, the macro fails and seems to not be interpreting the newlines. Once I manually doubleclick inside a cell though to where the text cursor appears then leave that cell to run the newline macro, it is then able to detect the newlines.
What's going on here? Do the characters have different uni-code values or something prior to double-clicking the cell? I have similar problems when trying to analyze the characters of a cell for other words as well only when the cell text was generated from a macro.
I suspect some of what you call newlines are carriage return characters ASCII 13. When you enter a carriage return character in a cell manually excel converts it into a new line character (ASCII 10). After reading your question, I verified this by entering the formula "=CHAR(13)" into cell A1 and then copied and pasted its value in place. I entered the formula "=CODE(A1)" in cell A2 to evaluate the ASCII code of the character in A1 (13 at this point). I then double clicked into A1 and pressed Enter and (guess what?) the character was changed into a new line character (ASCII 10). I suspected the same would happen with CHAR(11), but that was not the case.
To solve your problem I suggest you first convert all occurances of Chr(13) to Chr(10) using something like
MyString = Replace(MyString, Chr(13), Chr(10))
' and if it were me, I would also add (just in case)
MyString = Replace(MyString, Chr(11), Chr(10))
In my experience some programs (e.g. Access reports if I am not mistaken) need a sequence of Chr(10) & Chr(13) (or the other way around) to physically display a new line in reports and therefore, if you pull a paragraph that has what appears to be 2 new line characters, then the actual string to achieve this would be Chr(10) & Chr(13) & Chr(10) & Chr(13) and in excel you end up with 4 new line characters. Hope this helps.
Edit:
In case this persists, a way I would use to debug the situation is by printing all chars with their values and read the character code at the place that's causing the issue with something like this (code not tested):
Dim s As String
Dim i as Integer
For i = 1 to Len(MyString)
s = Mid$(MyString, i, 1)
Debug.Print s & ", " & Asc(s) 'Or perhaps AscW(s) for unicode
Next i
I have cells that look like this: 1000 (1.0) and I would like to format the first part of the cell with commas separating the thousands, i.e 1,000 (1.0).
I've tried using the text function in a formula i.e. =text(A1,"0,000") or =text(A1,"#,###") but this didn't add a comma.
Excel sees the cell as a text string and as such it cannot be formatted. You need to parse the string and put it back together:
=TEXT(LEFT(A1,FIND("(",A1)-1),"#,##0") & " " & MID(A1,FIND("(",A1),20)
Example: =i8&", "&i9&", "&i10 but don't add ", " for any Empty cells.
Result if all (three) cells have data: data, data, data.
Not the result I want, but I am getting: , , data (when the two preceding cells are empty).
TRIM doesn't remove the , ,, nor does Find/Replace.
To join three columns I use:
=i8 & i9 & i10
To break them up with a comma and a space I use:
=i8 & ", " & i9 & ", " & i10
But when one of the cells is empty I don't want ", " before the information from a subsequent column nor ", , " when it is two empty cells.
I have tried to sort on the comma and the space but sometimes that search finds nothing. Besides, I don't want to replace 'comma space' when there IS data. I tried TRIM but that didn't help since it seemed to have no effect, even when it was just an effort to remove one empty space.
Unless someone has a reliable TRIM statement for this?
I would prefer to have a statement that skips empty cells and doesn't include the ", " (comma and space) where there isn't data.
Basically the idea is joining three telephone numbers: "Home Work Cell" into "(515) 555-1234 (H), 515 555-9876 (W), etc."
You can use:
concatenate with a space
then TRIM()
then SUBSTITUTE
=SUBSTITUTE(TRIM(A1 & " " & B1 & " " & C1)," ",", ")