Consolidating Consecutive Date Rows

pawville

New Member
Joined
Apr 5, 2006
Messages
18
Hi All,
I am working with an excel file that shows daily whether an individual is checked into a shelter. The dates are often consecutive. I am trying to merge rows to reflect a true length of stay, not daily. here is what my data looks like:
First Last SSN DOB Entry Date Exit Date
Jane Doe 111111111 1/11/1111 4/1/2009 4/1/2009
Jane Doe 111111111 1/11/1111 4/2/2009 4/2/2009
Jane Doe 111111111 1/11/1111 4/3/2009 4/3/2009
Jane Doe 111111111 1/11/1111 4/4/2009 4/4/2009
Jane Doe 111111111 1/11/1111 4/5/2009 4/5/2009
Jane Doe 111111111 1/11/1111 4/6/2009 4/6/2009
Jane Doe 111111111 1/11/1111 4/7/2009 4/7/2009
Jane Doe 111111111 1/11/1111 4/8/2009 4/8/2009
Jane Doe 111111111 1/11/1111 4/9/2009 4/9/2009
Jane Doe 111111111 1/11/1111 4/10/2009 4/10/2009
Jane Doe 111111111 1/11/1111 4/12/2009 4/12/2009
Jane Doe 111111111 1/11/1111 4/13/2009 4/13/2009
Jane Doe 111111111 1/11/1111 4/14/2009 4/14/2009
Jane Doe 111111111 1/11/1111 4/15/2009 4/15/2009
Jane Doe 111111111 1/11/1111 4/16/2009 4/19/2009
Jane Doe 111111111 1/11/1111 4/21/2009 4/22/2009

Here is what I would like it to look like:
First Last SSN DOB Entry Date Exit Date
Jane Doe 111111111 1/11/1111 4/1/2009 4/10/2009
Jane Doe 111111111 1/11/1111 4/12/2009 4/19/2009
Jane Doe 111111111 1/11/1111 4/21/2009 4/22/2009

Does anyone have any suggestions on how I can accomplish this with a macro or otherwise so I don't have to manually go through a year's worth of data? Thanks for your help and time.
Sincerely,
Fred
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Assuming that Column A to Column F contains the data, and Row 1 contains the headers, try...

Code:
Sub test()

Dim LastRow As Long
Dim i As Long

Application.ScreenUpdating = False

LastRow = Cells(Rows.Count, 1).End(xlUp).Row

For i = LastRow To 3 Step -1
    If Cells(i - 1, "F") + 1 = Cells(i, "E") Then
       Cells(i, "E") = Cells(i - 1, "E")
       Rows(i - 1).Delete
    End If
Next i

Application.ScreenUpdating = False

End Sub
 
Upvote 0
Thank you Domenic,
I will try this tomorrow. Your assumption regarding row headers and columns was correct. My Data has many more columns so can I replace the "E" and the "F" in your code to reflect the appropriate columns that contain the dates?

Thanks again.
Sincerely,
Fred
 
Upvote 0
Thank you again Domenic!
At quick glance it appears to have worked perfectly. I will look at it in more detail just to be sure. This process will be repetitive on a monthly basis where I will have to add new data to previously consolidated data. I have combined two files and run the macro and have gotten an error:

Run-time Error '13':
Type Mismatch

I take this to mean that somewhere in my separate spreadsheets the data type for a field does not match (for example in one spreadsheet SSN is stored as text and in the other it is stored as a number). Would you agree?

If I change the data type to be the same (text and text) in my combined spreadsheet and run the macro, will that eliminate the error?

Thank you again.
Sincerely,
Fred
 
Upvote 0
The error likely occurs because one or more dates from your second file are not true date values. Two questions...

1) How does the date actually appear in the cell?

2) What does the following formula return?

=ISNUMBER(E100)

...where E100 represents a cell that contains a supposed date from your second file.
 
Upvote 0
For the two columns that the code is checking, they are all stored as numbers (the value for the formula =isnumber(e100) is "TRUE".

I do have some other date columns which returned a "FALSE" value. All of them appear to be null or blank.

Does that help?

Thanks again.
 
Upvote 0
Hi Domenic,

Those dates are not located in the target columns. One is Date of Birth and the other is Status Date.

The cells are blank. As far as I can tell they have no value in them. I receive the data as a .dbf and open the file with excel. So I believe initially everything is formatted as text.

Let me know if I can provide additional information. Thank you again.
Sincerely,
Fred
 
Upvote 0
Just to be sure, let's try one more thing. Assuming that Column E and Column F contain the entry and exist dates, and that the data starts in Row 1, try the following formula (adjust the range, accordingly)...

=SUMPRODUCT(--ISNUMBER(E2:F100))=ROWS(E2:F100)*2

If it returns FALSE, then there's one or more dates in the range that's not a true date value and, hence, the error. What does it return?
 
Upvote 0

Forum statistics

Threads
1,215,759
Messages
6,126,728
Members
449,332
Latest member
nokoloina

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