If you could please help me with this data sorting problem.
I am a doctor who does research in haematological malignancies. My research database is a huge Excel workbook. It expanded so much that the data had to be in different sheets. When putting the data into the sheets I did something very stupid which I try to correct now (unsuccessfully).
My original mistake was to use different sheets for different kinds of events, instead of just adding events by the date to the next sheet. It is now very difficult to follow the history of one case, you have to jump back and forward between the sheets to do so. Every sheet has data for one kind of event for all cases. The rows in the sheets contain the case #, the date when the event happened and 135 variable columns . There are 375 rows in each sheet.
So now I have 9 sheets (Primary Event, Serious Event 1, Serious Event 2, Serious Event 3, Serious Event 4, Mild Event 1, Mild Event 2, Mild Event 3, Mild Event 4). I would like to change the sheets to be based on the dates when the events took place:
Event-1, Event-2, Primary Event, Event+2, Event+3, Event+4, Event+5, Event+6, Event+7
To illustrate the problem, let's say there are three cases, three variables and four sheets only – if you could solve this it would be applicaple to 375 cases, 137 variables and 9 sheets as well. Here’s how it looks like now:
Note that Case #2 and #3 didn’t have a second Serious event and Case #3 did not have a mild event 1. Also note that Case #1 had a “Serious Event 1” prior to the Primary one.
I want to have my database to copy and sort the entire rows based on the date, and then paste the row to the relevant sheet. It would to look like this:
I have tried to achieve this with If...Then directives in VB, but they become extremely nested and I frankly get lost in the code. Is there a way to make a simpler VBA-code to copy these rows into the new sheets based on the event dates?
I would be extremely grateful for help,
Björn Wahlin MD
I am a doctor who does research in haematological malignancies. My research database is a huge Excel workbook. It expanded so much that the data had to be in different sheets. When putting the data into the sheets I did something very stupid which I try to correct now (unsuccessfully).
My original mistake was to use different sheets for different kinds of events, instead of just adding events by the date to the next sheet. It is now very difficult to follow the history of one case, you have to jump back and forward between the sheets to do so. Every sheet has data for one kind of event for all cases. The rows in the sheets contain the case #, the date when the event happened and 135 variable columns . There are 375 rows in each sheet.
So now I have 9 sheets (Primary Event, Serious Event 1, Serious Event 2, Serious Event 3, Serious Event 4, Mild Event 1, Mild Event 2, Mild Event 3, Mild Event 4). I would like to change the sheets to be based on the dates when the events took place:
Event-1, Event-2, Primary Event, Event+2, Event+3, Event+4, Event+5, Event+6, Event+7
To illustrate the problem, let's say there are three cases, three variables and four sheets only – if you could solve this it would be applicaple to 375 cases, 137 variables and 9 sheets as well. Here’s how it looks like now:
Code:
Sheets(”Primary Event”)
Case Date Health Kind of event
#1 25 May 1998 1 Primary
#2 1 June 2005 5 Primary
#3 12 Aug 2001 2 Primary
Sheets(”Serious Event 1”)
Case Date Health Kind of event
#1 25 Dec 1995 2 Serious
#2 4 Oct 2005 3 Serious
#3 11 Sept 2003 4 Serious
Sheets(”Serious Event 2”)
Case Date Health Kind of event
#1 25 Dec 1999 2 Serious
#2
#3
Sheets(”Mild Event 1”)
Case Date Health Kind of event
#1 2 Nov 1998 5 Mild
#2 21 Nov 2005 5 Mild
#3
I want to have my database to copy and sort the entire rows based on the date, and then paste the row to the relevant sheet. It would to look like this:
Code:
Sheets(“Event-1”)
Case Date Health Kind of event
#1 25 Dec 1995 2 Serious
#2
#3
Sheets(“Primary Event”)(it will not change)
Case Date Health Kind of event
#1 25 May 1998 1 Primary
#2 1 June 2005 5 Primary
#3 12 Aug 2001 2 Primary
Sheets(“Event+1”)
Case Date Health Kind of event
#1 2 Nov 1998 5 Mild
#2 4 Oct 2005 3 Serious
#3 11 Sept 2003 4 Serious
Sheets(“Event+2”)
Case Date Health Kind of event
#1 25 Dec 1999 2 Serious
#2 21 Nov 2005 5 Mild
#3
I would be extremely grateful for help,
Björn Wahlin MD