Sometimes you have formatted reports that you need to transform into a data table in order to get more statistics or make a pivot.
Here you can find the sample file used in this post. You can copy from the Data Template sheet to exercise yourself.
The file was used also for showing how to Filter bold text.
What we have and what we need
We have something like below and we need to add 4 new columns:
- Date (1): the value in cell B2
- Other header info (1): the value in cell B3
- Code (2): the numbers from column A
- Description (2): the text from column A
We’ll add all the new info to the end of the data.
To start, select all sheet and apply Autofilter.
Step 1. Add the Date and Other header info
This one should be very simple:
- Select all lines that are not blank. You can use column B here.
- Put the new columns name on col O and P.
- Either copy/type the Date and Other header info or use references: =$B$2 for Date and =$B$3 for Other header info. Notices the $ sign – we need an absolute reference.
- Autofill for all selected lines
Step 2. Separate the Code from Description
- If the data is filtered, un-filter it
- Select column A and go to Data=> Text to columns. Here are steps on each screen of the wizard:
- Select Delimited
- Tick Semicolon
- In Destination field type (or fill in by mouse click) =$Q$1. This way you have both the original column and the split data
- Add names to column Q and R: Code and Description and delete the info in cells Q2 and Q3.
- Remove and apply again Autofilter in order to have these 2 new columns too.
Step 3. Create Code and Description columns
- We need to get rid of all blank line so filter again on column C = blank and column Q = blank. Delete the blank lines and un-filter the data.
- Keep in mind the reference of the first code, here is Q4
- Filter the data on column B <> blank
- Go on Code column, Q, and select the first cell on a row lower than 4. Here it will be Q6.
- In this cell, type the reference of the first Code, Q4
- We can use Autofill right to add the same formula to Description column, R. Either use mouse or Ctrl+r.
- Autofill for all lines. Your data will look like this
- Once you are happy with it, copy and paste it as values. Then you can delete the extra rows and columns.
In case you need to process multiple files this option is too time consuming. You can use VBA instead, see here how.