Extract contents between two sub strings.

nemo1478

New Member
Joined
Feb 14, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
Reserve power at site: x
Time of A Failure: y
Time of A Restoration: z
Duration of A Failure: a
Time of Site Failure: b
Time of Site Restoration: c
Duration of Site Failure: d
Duration of Reserve Power: e

In the above sample text I want to be able to extract the data (x,y,z,a,b,c,d,e) between the various sub strings and place them into separate columns. I have found solutions that will extract the contents between two words or two characters but not between entire strings of text. Can anyone suggest how this can be done or an even better way of approaching this?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to Mr. Excel.
In your example, are those lines separate strings in, say, the A column, 8 rows?
Are you wanting to extract whatever is AFTER the colon on each line and put them in 8 subsequent columns?
 
Upvote 0
It's 8 rows in 1 cell (really 1 long string with word wrap applied) and yes I just want to extract what is after the colon on each line in 8 other columns
 
Upvote 0
It looks more like each line ends with an ALT+Enter -- is that the case?
 
Upvote 0
Assuming your first data cell is A1 and that a data cell always contains less than 300 characters total, then put this formula in cell B1 and copy it across...

=TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1,CHAR(10),":"),":",REPT(" ",300)),(2*COLUMNS($B1:B1)-1)*300,300))
 
Upvote 0
Here another formula for you to consider:

varios 14feb2020.xlsm
ABCDEFGHI
2Reserve power at site: x Time of A Failure: y Time of A Restoration: z Duration of A Failure: a Time of Site Failure: b Time of Site Restoration: c Duration of Site Failure: d Duration of Reserve Power: exyzabcde
sheet
Cell Formulas
RangeFormula
B2:I2B2=TRIM(MID(SUBSTITUTE(SUBSTITUTE($A2,CHAR(10),REPT(" ",LEN($A2)),COLUMNS($B:B)),":",REPT(" ",LEN($A2)),COLUMNS($B:B)),LEN($A2)+1,LEN($A2)))
 
Upvote 0
My amateur VBA approach so that you don't have to drag the formula to the right.
Assumes original data is in A1 (adjust accordingly). A VBA ACE here will make this considerably easier, I'm sure.

Code:
Sub SplitLF()
Dim sData As String, sStr() As String, i As Integer, nStr As String, ubnd As Variant
sData = Range("A1")
sStr = Split(sData, Chr(10))
ubnd = UBound(sStr)
For i = 0 To ubnd
 nStr = Right(sStr(i), Len(sStr(i)) - (InStr(sStr(i), ":") + 1))
 Cells(1, i + 2) = nStr
Next
End Sub
 
Upvote 0
You guys work fast! I just made one mistake. I left out the very first line of the cell which I have now included below. I think this will affect the formula.

Power Details:-
Reserve power at site: x
Time of A Failure: y
Time of A Restoration: z
Duration of A Failure: a
Time of Site Failure: b
Time of Site Restoration: c
Duration of Site Failure: d
Duration of Reserve Power: e
 
Upvote 0
kweaver I really really appreciate the effort and time you took to respond to my problem but honestly I don't have a clue how to use that code in the excel spreadsheet.
 
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,695
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top