In the cell below, I want to get whatever is separated by a comma to come to a new line. I can add these line breaks manually with alt+enter, but this time I want to automate it.
BCM:Open,Event:Site XXXX is down,Service Affected :2G,Impact :Coverage
Restored at XXXX Area,Reason:Under Investigation,Recovery Time :30
Minutes,Start time:14:25:13,End Time:15:18:03,Duration:00:52:50,SLA:1
Hour.
For some reason, none of the above worked for me. This DID however:
Selected the range of cells I needed to replace.
Go to Home > Find & Select > Replace or Ctrl + H
Find what: ,
Replace with: CTRL + SHIFT + J
Click Replace All
Somehow CTRL + SHIFT + J is registered as a linebreak.
To replace commas with newline characters use this formula (assuming that the text to be altered is in cell A1):
=SUBSTITUTE(A1,",",CHAR(10))
You may have to then alter the row height to see all of the values in the cell
I've left a comment about the other part of your question
Edit: here's a screenshot of this working - I had to turn on "Wrap Text" in the "Format Cells" dialog.
Use
=SUBSTITUTE(A1,",",CHAR(10) & CHAR(13))
This will replace each comma with a new line. Change A1 to the cell you are referencing.
You can also do this without VBA from the find/replace dialogue box. My answer was at https://stackoverflow.com/a/6116681/509840 .
Windows (unlike some other OS's, like Linux), uses CR+LF for line breaks:
CR = 13 = 0x0D = ^M = \r = carriage return
LF = 10 = 0x0A = ^J = \n = new line
The characters need to be in that order, if you want the line breaks to be consistently visible when copied to other Windows programs. So the Excel function would be:
=SUBSTITUTE(A1,",",CHAR(13) & CHAR(10))
Related
I have a value like "NetWorker 8.2.3.1.Build."
And I have to get only the value "NetWorker 8.2.3.1" in Excel.
How can I achieve this?
A1 = NetWorker 8.2.3.1.Build
=SUBSTITUTE(A1,".Build",)
or
=LEFT(A1,COUNT(FIND(".",A1,ROW($1:$36)))-1)
or
=TRIM(LEFT(SUBSTITUTE(A1,".",REPT(" ",99),4),99))
Another possibility (if .Build. is not anywhere else in your excel):
CTRL + A
CTRL + F
search for .Build.
Replace by ''
(nothing within the replace field)
In the cell below, I want to get whatever is separated by a comma to come to a new line. I can add these line breaks manually with alt+enter, but this time I want to automate it.
BCM:Open,Event:Site XXXX is down,Service Affected :2G,Impact :Coverage
Restored at XXXX Area,Reason:Under Investigation,Recovery Time :30
Minutes,Start time:14:25:13,End Time:15:18:03,Duration:00:52:50,SLA:1
Hour.
For some reason, none of the above worked for me. This DID however:
Selected the range of cells I needed to replace.
Go to Home > Find & Select > Replace or Ctrl + H
Find what: ,
Replace with: CTRL + SHIFT + J
Click Replace All
Somehow CTRL + SHIFT + J is registered as a linebreak.
To replace commas with newline characters use this formula (assuming that the text to be altered is in cell A1):
=SUBSTITUTE(A1,",",CHAR(10))
You may have to then alter the row height to see all of the values in the cell
I've left a comment about the other part of your question
Edit: here's a screenshot of this working - I had to turn on "Wrap Text" in the "Format Cells" dialog.
Use
=SUBSTITUTE(A1,",",CHAR(10) & CHAR(13))
This will replace each comma with a new line. Change A1 to the cell you are referencing.
You can also do this without VBA from the find/replace dialogue box. My answer was at https://stackoverflow.com/a/6116681/509840 .
Windows (unlike some other OS's, like Linux), uses CR+LF for line breaks:
CR = 13 = 0x0D = ^M = \r = carriage return
LF = 10 = 0x0A = ^J = \n = new line
The characters need to be in that order, if you want the line breaks to be consistently visible when copied to other Windows programs. So the Excel function would be:
=SUBSTITUTE(A1,",",CHAR(13) & CHAR(10))
I have a column with about 5k rows that I need to add slashes to. I need to add slashes to the first, second, and last space (" ") in the cell. Each cell has different lengths so there are different amounts of spaces between the second and last in each row.
Here's an example of some rows
NYLA D DURA FEMUR BCN LG
NULO D FZD GF BF 5oz
OMNI D BRTSH SLP LD GRN 4ft
OMNI D LIGHT S-HOOK
OMNI D SS BOWL 3qt
I need these converted to
NYLA/D/DURA FEMUR BCN/LG
NULO/D/FZD GF BF/5oz
OMNI/D/BRTSH SLP LD GRN/4ft
OMNI/D/LIGHT S-HOOK
OMNI/D/SS BOWL/3qt
I have tried using the substitute formula but that will only add one slash when I need to add 1-3. I'm not sure if nesting the substitute formula is possible in this scenario. If so, that should do it but I can't get it to work.
Nested SUBSTITUTE is the way to go:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1," ","/",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))," ","/",2)," ","/",1)
You can achieve this with the following formula:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1," ","/",LEN(SUBSTITUTE(A1," "," "))-LEN(A1))," ","/",1)," ","/",1)
It replaces the last instance of " " followed by the first two instances.
This might however return an error if there are less than three " " in the string.
I have an issue that I've not been able to figure out even with many of the ideas presented in other posts. My data comes in Excel and here are examples of each manner that any given cell might have the data:
4days 4hrs 41mins 29seconds
23hrs 43mins 4seconds
2hrs 2mins
52mins 16seconds
The end result would be to calculate the total minutes while allowing seconds to be ignored, so that the previous values would end up as follows:
6041
52
1423
122
Would anyone have an idea how to go about that?
Thanks for the assistance!
Bit tedious (and assumes units are always plural - also produces results in different order to example) but, with formulae only, if your data is in column A, in B1 and copied down:
="="&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"days","*1440+"),"hrs","*60+"),"mins","*1+"),"seconds","*0")," ","")&0
then Copy B and Paste Special values into C and apply Text to Columns to C with Tab as the delimiter.
This array formula** should also work:
=SUM(IFERROR(0+MID(REPT(" ",31)&SUBSTITUTE(A1&"dayhrminsecond"," ",REPT(" ",31)),FIND({"day","hr","min","second"},REPT(" ",31)&SUBSTITUTE(A1&"dayhrminsecond"," ",REPT(" ",31)))-31,31),0)*{1440,60,1,0})
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
The easiest option is probably VBA with a regular expression. You can then easily find each of the fields, and do the maths.
If you want to stick to "pure" Excel, then it seems to only option is to use SEARCH or FIND to find the position of each of the "days", "hrs", "mins" in the text (you may have to check if they're always plural). Then use MID with the position found above to extract the different components. See http://office.microsoft.com/en-gb/excel-help/split-text-among-columns-by-using-functions-HA010102341.aspx for similar examples.
But there's quite a bit of work to handle the cases where some components are missing, so either you'll use quite a few cells, so you'll get a very complex formula...
Here is a User Defined Function, written in VBA, which takes your string as the argument and returns the number of minutes. Only the first characters of the time interval names are checked (e.g. d, h, m) as this seems to provide sufficient discrimination.
To enter this User Defined Function (UDF), opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.
To use this User Defined Function (UDF), enter a formula like
=SumMinutes(A1)
in some cell.
Option Explicit
Function SumMinutes(S As String) As Long
Dim RE As Object, MC As Object
Dim lMins As Long
Dim I As Long
Set RE = CreateObject("vbscript.regexp")
With RE
.Pattern = "(\d+)(?=\s*d)|(\d+)(?=\s*h)|(\d+)(?=\s*m)"
.Global = True
.ignorecase = True
If .test(S) = True Then
Set MC = .Execute(S)
For I = 0 To MC.Count - 1
With MC(I)
lMins = lMins + _
.submatches(0) * 1440 + _
.submatches(1) * 60 + _
.submatches(2)
End With
Next I
End If
End With
SumMinutes = lMins
End Function
I have the following code:
a = 123
p.value 0.123
p.long.name = "abc"
How can I align each line like shown below in vim?
a = 123
p.value = 0.123
p.long.name = "abc"
Thanks for any hints.
Without plugin:
:%s/=/ &/
:%s/\%13c\s\+=/=
First command will insert spaces before first equal signs on all lines, second one will remove all spaces before an equal sign at 13th column. You could also use Visual block selection and <..... to shift left as many times as necessary.
However this is really unclean. With the tabular plugin you just type :Tab /=/ and this will do the work and the range will be calculated automatically (greatest range around the cursor in which all lines match the pattern).