Forum Discussion
I_need_help_544
Feb 04, 2024Copper Contributor
Separating multiple lines in same cell into separate cells
Hi all, I have an urgent query that I have been working on for hours but to no avail.
I have a few hundred separate addresses in excel (say in the range A1-A200), arranged over 4-5 lines within each cell. An example is below in Cell A1;
A.N. Other
54 Bee Road
Anytown
Anywhere
LE4 6EY
Each of the 200 cells that contain the above addresses need each line of the address to be in a separate cell - so in the example above where this address is in Cell A1, I would need the first line (A.N. Other) to present in Cell B1, the 2nd line of the address (54 Bee Road) to present in Cell C1, etc all the way to there the 5th Line (LE4 6EY Postcode) to present in Cell F1.
The issue causing the difficulty -
Normally, 'Text to Column' should be able to resolve this. However, these addresses have been imported in csv format from another program and so even though the address is arranged over a number of lines, there is no a line break at the end of each line. Due to there being no line break, I am unable to use the 'Text to Columns' functionality to arrange the data into separate cells in the manner that I would like.
Apart from me manually going in and copying and pasting line by line (which will take me at least 1-2 days), is there an easy way of doing this? The key problem is linked to there being no line breaks at the end of each line and so I have been unable to do this with 'Text to Columns' functionality.
Any help on this would be gratefully appreciated.
J_Mendez92 wrote: ``This is the link for the file``
Perfect! Thanks.
But please unmark my previous reply as "best response", if you can. It is not (yet) a response to your question(s).
-----
To clarify, I believe you are asking two questions.
The following image shows what you posted previously, followed by the formulas that we find in your Excel file. See the attached Excel file for details.
For clarity, I have moved the Conditional Formatting formulas into rows 5 and 13, where they can be seen and discussed.
Formulas:
A1: =SUM(A2:A3)
B1: =AVERAGE(B2:B3)
E1: =AVERAGE(E2:E3)=SUM(B1:D1)
F1: =SUM(1,B1:D1)*A1
E2: =SUM(B2:D2)
F2: =A2*(1+E2)
F5: =SUM(F2:F3)
G5: =F5=F1
-----
Your thread title asks if the sum of averages is the same as the average of the sums.
As I explained previously: in general, no.
But your example demonstrates the exception to the rule, namely: when the divisor of each average is the same.
This is demonstrated in the yellow-highlighted formulas in E1 and E9. For example (E1):
AVERAGE(E2:E3) = SUM(B1:D1)
The algebra is:
e2 = b2+c2+d2
e3 = b3+c3+d3
average(e2,e3) = (e2+e3)/2 = (b2+c2+d2+b3+c3+d3)/2
sum(b1,c1,d1) = (b2+b3)/2 + (c2+c3)/2 + (d2+d3)/2 = (b2+b3+c2+c3+d2+d3)/2
Rearranging terms in the last expression, we can see that they are the same.
-----
However, that has nothing to do with the real question you ask, namely: why does F1 = F5, but F9 <> F13?
The difference is because A2 = A3, but A10 <> A11.
(PS.... That difference can be large. For example, set A10=10 and A11=20; thus, A9=30. Then we can see a large difference between F9 and F13, which might be less confusing to the casual reader.)
This is demonstrated by the formulas in G5 and G13. They are effectively (G5):
SUM(F2:F3) = SUM(1,B1:D1)*A1
The algebra is:
f2 = a2*(1+b2+c2+d2)
f3 = a3*(1+b3+c3+d3)
sum(f2,f3) = a2*(1+b2+c2+d2) + a3*(1+b3+c3+d3)
And that is the correct sum to use.
a1*sum(1,b1,c1,d1) = (a2+a3) * (1 + (b2+c2+d2+b3+c3+d3)/2)
relying on the average equality exception demonstrated above.
In general when a2<>a3, we can see that the last formula is unrelated to the sum(f2,f3) formula.
But in the exceptional case when a2=a3, we can show that the two formulas are equivalent by replacing a3 with a2:
sum(f2,f3) = a2*(1+b2+c2+d2) + a2*(1+b3+c3+d3)
= a2 * (2 + b2+c2+d2+b3+c3+d3)
= 2 * a2 * (2 + b2+c2+d2+b3+c3+d3) / 2
=(a2+a2) * (1 + (b2+c2+d2+b3+c3+d3)/2)
=a1*sum(1,b1,c1,d1)
-----
I hope you followed the algebra.
To summarize:
1. Both E1 and E9 are TRUE because of the exceptional case when each average has the same divisor.
2. F1 = F5 because of the exceptional case when a2=a3.
5 Replies
Sort By
Could you attach a small sample workbook with a few of such cells (without sensitive data), or if that is not possible, make it available through OneDrive, Google Drive, Dropbox or similar?
- I_need_help_544Copper Contributor
Thank you for your response.
I can't see how to attach my excel file so please see below table for what I'm after and an example in the first row (addresses are fictitious);
Full Address before any separating of lines Address Town County Postcode 999 Cann Hall Road
Leytonstone
London
E11 3EE999 Cann Hall Road Leytonstone London E11 3EE Example Row 999 Lonsdale Avenue
East Ham
Newham London
E6 3EE999 Almond Close
82-84 Forest Road
Walthamstow London
E17 3EE999 Margery Park Road
Forest Gate
London
E7 9EE999 High Street
Wanstead
London
E11 2EE- djclementsBronze Contributor
I_need_help_544 Are you absolutely sure there are no line feed characters (CHAR(10)) used to separate each line? Can you do a quick test to confirm this? For example, in cell B2 try the following:
=SUBSTITUTE(A2, CHAR(10), ";")
If the above formula returns the address with each line separated by semi-colons, then the original address does in fact contain line feed characters, and the Text to Columns feature can be used by selecting "Other" delimiter and pressing Ctrl+J to specify the line feed character.
If there are truly no line feed characters present, you will need to identify what character(s) are being used to create each line break. For example, if the address beginning with "A.N. Other" is in cell A2, the 11th character should be the line feed character, in which case you could try the following formula to reveal the character code:
=CODE(MID(A2, 11, 1))
Or, if you have Excel for MS365, the following array formula may help by identifying each and every character in the address with their corresponding character codes:
=LET( arr, MID(A2, SEQUENCE(, LEN(A2)), 1), VSTACK(arr, CODE(arr)) )
These are merely suggestions to help identify the character(s) being used to separate each line. Without access to your actual file, I'm afraid it's the best I can offer at this time.