I have a SQL database of illnesses (Records of 9,000) but the illnesses are copy-pasted into a single field and arranged in numbers. From here we always extract to Excel to manipulate the data. My problem now is to put these illnesses into separate cell compartment in excel so that we can filter it properly. I have only tried the Text-to-Column in Excel but it does not do the job.
And this is what I'm trying to achieve:
I hope it makes sense. Thank you.
This is possible in Get&Transform if you're on a recent version of Excel.
Get Data from range
Right Click the Column>Split Column>By Delimiter
In advanced options you can split by row and get the "new line" character i.e. cr/lf
Comorbidity
Intro
Wikipedia: In medicine, comorbidity is the presence of one or more additional diseases or disorders co-occurring with (that is, concomitant or concurrent with) a primary disease or disorder; in the countable sense of the term, a comorbidity (plural comorbidities) is each additional disorder or disease.
The Code
Beware: There is no error handling, so if something goes wrong just don't save anything. Close without saving and try again.
The code was tested and works fine with Excel 2003 and should work fine with all newer versions, too.
The code blocks starting with
' str1 =
are just for debugging, a kind of 'subtotals' and can be deleted if you wish.Some additional info
How to put more lines into one cell
You have to hold the left ALT key and press enter after each line.
How I got the delimiter
When you go into a cell (click in the formula bar) e.g. cell 'A1' with more lines (bulk data), you select the end of a line expanding over the 'invisible' kind of 'space looking' character right after the 'visible' part and copy it. Then paste it into another cell e.g. A2. Now in e.g. cell A3 write the formula
=CODE(A2)
and the result will be 10. So in VBA this means you choose this character by using the Chr Function:Chr(10)
(in Excel this is=CHAR(10)
. BTW the character is called Line Feed (LF) or New Line (NL). For other character codes look here.Comorbidity 2.0
Intro
Wikipedia: In medicine, comorbidity is the presence of one or more additional diseases or disorders co-occurring with (that is, concomitant or concurrent with) a primary disease or disorder; in the countable sense of the term, a comorbidity (plural comorbidities) is each additional disorder or disease.
Since you couldn't get the first script to work I could only conclude that you might have a different line delimiter than the Line Feed at the end of each line in the multi-line cells. So I wrote an improved version of the whole thing and added a function to determine the delimiter for each cell. Now you only have to select a column e.g. A, B, or T (in your sample picture) etc. in the customize section of the code:
... and the code does the rest itself.
The Code
Some additional info
To put more lines into a cell you have to hold the left ALT key and press enter after each line.
For character codes look here.