Macro to combine start and end dates of resoucres into one line

latkan

New Member
Joined
Nov 7, 2013
Messages
10

<tbody>
[TD="class: votecell"][/TD]
[TD="class: postcell"] I work with a resourcing ledger which is also used for other financial purposes. As a result of the financial phases each resource in the file is split over 4-5 rows. What I would like to do is create a macro which finds their start date and corresponding end date on the next few rows and combines them whilst deleting the other rows and dates in between which show the interim date.


Another twist is that the file also holds roles yet to be fulfilled and are therefore just simply TBC.


I also need to do the same for the TBCs but instead will use the name of the role rather than the resource name to do the deletion of in between dates I have no idea how to go about this

So far I have created the following macros which goes through the dates and as long as they are in ldest to newest order - will seek out the lines which follow on from the original line. It does not however combine the start and final end date

Sub LoopRange3()

'Start at the currently selected cell
x = ActiveCell.Row
y = x + 1

'Outside loop
Do While Cells(x, 1).Value <> ""
'Inside loop
Do While Cells(y, 1).Value <> ""
'Test for duplication:
'If the values of the third column (C) and the fifth column (E) match in two rows
'delete the second row of the pair, otherwise go to the next row until the end
If (Cells(x, 3).Value = Cells(y, 3).Value) _
And (Cells(x, 5).Value = Cells(y, 5).Value) _
And (Cells(x, 7).Value = Cells(y, 7).Value) _
And (Cells(x, 9).Value = Cells(y, 9).Value) _
And (Cells(x, 10).Value = Cells(y, 10).Value) _
And (Cells(x, 13).Value <> Cells(y, 13).Value) _
And (Cells(y, 13).Value >= Cells(x, 14).Value) _
Then

'FOR DUPLICATE DELETION: Uncommment the following line by removing the apostrophe
'Cells(y, 3).EntireRow.Delete

'Shade the entire row green if it's a duplicate
'FOR DUPLICATE DELETION: Make the following line a comment by adding an apostrophe
Cells(y, 3).EntireRow.Interior.ColorIndex = 3

Else

'FOR DUPLICATE DELETION: Uncomment the following line by removing the apostrophe

End If

'FOR DUPLICATE DELETION: Make the following line a comment by adding an apostrophe
y = y + 1
Loop
'increase the value of x by 1 to move the loop starting point to the next row
x = x + 1
'reset y so it starts at the next row
y = x + 1
Loop

End Sub


:confused:



any help would be great

[/TD]

</tbody>
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
latkan,

Welcome to the MrExcel forum.

What version of Excel and Windows are you using?

Can you post a screenshot of the raw data worksheet, and, post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel HTML Maker

Or, when using Internet Explorer, just put borders around your data in Excel and copy those cells into your post.
See reply #2 the BLUE text in the following link:
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045

If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.


If posting VBA code, please use Code Tags - like this:

[code]

Paste your code here.

[/code]
 
Upvote 0
latkan,

Welcome to the MrExcel forum.

What version of Excel and Windows are you using?

Can you post a screenshot of the raw data worksheet, and, post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel HTML Maker

Or, when using Internet Explorer, just put borders around your data in Excel and copy those cells into your post.
See reply #2 the BLUE text in the following link:
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045

If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.


If posting VBA code, please use Code Tags - like this:

[code]

Paste your code here.

[/code]

Hi Hiker95

Thanks for your advice

so far I am using Excel 2013. You are correct if I add an image of the work I am looking at then it may help


-- removed inline image ---



So as you can see the same person is split over a few rows and I need to find their start and end date and minimise this to one line. This is also true for the roles we are searching for.

ANY help would be great.
 
Upvote 0
latkan,

Please do not quote entire replies from your helper. When quoting follow these guidelines:
1. Quote ONLY if it is needed to add clarity or context for your reply. If so, then
2. Quote ONLY the specific part of the post that is relevant - - not the entire post.

This will keep thread clutter to a minimum and make the discussion easier to follow.


Can we have another workbook with:
1. the raw data worksheet
2. and, an additional worksheet (manually formatted by you) with the results that you are looking for?
 
Upvote 0
latkan,

Your latest workbook only contains one worksheet?


Excel 2007
FGHIJKLM
2Unique IDProject Role NameFull NameDivisionSub DivisionStatusStart DateEnd Date
31.0Marketing AnalystJane AustenFinanceLedgerActive1-Nov-134-Jan-14
445.0Marketing AnalystJane AustenFinanceLedgerScheduled5-Jan-1431-May-14
51334.0Marketing AnalystJane AustenFinanceLedgerScheduled1-Jun-1429-Sep-14
6649.0Marketing AnalystJim MurrayHRCustomer CareActive29-Jun-1321-Jan-14
7677.0Marketing AnalystJim MurrayHRCustomer CareScheduled22-Jan-144-Nov-14
8453.0Marketing AnalystJoe BloggsMarketingSalesActive26-Jul-1328-Dec-13
94685.0Marketing AnalystJoe BloggsMarketingSalesScheduled28-Dec-131-Feb-14
1033.0ManagerTBCMerchandisingShop RetailSearching22-Nov-131-Feb-14
113888.0ManagerTBCMerchandisingShop RetailSearching2-Feb-1426-Apr-14
124098.0ManagerTBCMerchandisingShop RetailSearching28-Apr-1430-Aug-14
135876.0Finance AnalystTBCMerchandisingShop RetailSearching28-Nov-1330-Sep-14
145432.0Finance AnalystTBCMerchandisingShop RetailSearching2-Oct-141-Apr-15
15342.0Offshore HRTBCLogisticsTransportSearching3-Feb-1413-Feb-15
16123.0Offshore HRTBCLogisticsTransportSearching6-Jan-1413-Feb-15
17321.0Offshore HRTBCLogisticsTransportSearching1-Jan-1430-Nov-14
185461.0Data AnalyserTBCLegalContractsSearching4-Nov-1313-Apr-15
193333.0Data AnalyserTBCLegalContractsSearching14-Apr-1513-Sep-15
201111.0Data AnalyserTBCLegalContractsSearching4-Nov-1313-Feb-15
Sheet1
 
Upvote 0
latkan,

If we start off with his:


Excel 2007
FGHIJKLM
2Unique IDProject Role NameFull NameDivisionSub DivisionStatusStart DateEnd Date
31.0Marketing AnalystJane AustenFinanceLedgerActive1-Nov-134-Jan-14
445.0Marketing AnalystJane AustenFinanceLedgerScheduled5-Jan-1431-May-14
51334.0Marketing AnalystJane AustenFinanceLedgerScheduled1-Jun-1429-Sep-14
6649.0Marketing AnalystJim MurrayHRCustomer CareActive29-Jun-1321-Jan-14
7677.0Marketing AnalystJim MurrayHRCustomer CareScheduled22-Jan-144-Nov-14
8453.0Marketing AnalystJoe BloggsMarketingSalesActive26-Jul-1328-Dec-13
94685.0Marketing AnalystJoe BloggsMarketingSalesScheduled28-Dec-131-Feb-14
1033.0ManagerTBCMerchandisingShop RetailSearching22-Nov-131-Feb-14
113888.0ManagerTBCMerchandisingShop RetailSearching2-Feb-1426-Apr-14
124098.0ManagerTBCMerchandisingShop RetailSearching28-Apr-1430-Aug-14
135876.0Finance AnalystTBCMerchandisingShop RetailSearching28-Nov-1330-Sep-14
145432.0Finance AnalystTBCMerchandisingShop RetailSearching2-Oct-141-Apr-15
15342.0Offshore HRTBCLogisticsTransportSearching3-Feb-1413-Feb-15
16123.0Offshore HRTBCLogisticsTransportSearching6-Jan-1413-Feb-15
17321.0Offshore HRTBCLogisticsTransportSearching1-Jan-1430-Nov-14
185461.0Data AnalyserTBCLegalContractsSearching4-Nov-1313-Apr-15
193333.0Data AnalyserTBCLegalContractsSearching14-Apr-1513-Sep-15
201111.0Data AnalyserTBCLegalContractsSearching4-Nov-1313-Feb-15
21
Sheet1


We end up with this - do you want to include the row with the BLUE background?


Excel 2007
FGHIJKLM
2Unique IDProject Role NameFull NameDivisionSub DivisionStatusStart DateEnd Date
31.0Marketing AnalystJane AustenFinanceLedgerActive1-Nov-1329-Sep-14
4649.0Marketing AnalystJim MurrayHRCustomer CareActive29-Jun-134-Nov-14
5453.0Marketing AnalystJoe BloggsMarketingSalesActive26-Jul-131-Feb-14
633.0ManagerTBCMerchandisingShop RetailSearching22-Nov-1326-Apr-14
75432.0Finance AnalystTBCMerchandisingShop RetailSearching28-Nov-131-Apr-15
8342.0Offshore HRTBCLogisticsTransportSearching1-Jan-1413-Feb-15
93333.0Data AnalyserTBCLegalContractsSearching4-Nov-1313-Sep-15
10
Sheet1
 
Last edited:
Upvote 0
latkan,


We end up with this - do you want to include the row with the BLUE background?

Excel 2007
FGHIJKLM
Marketing AnalystJane AustenFinanceLedger
Marketing AnalystJim MurrayHRCustomer Care
Marketing AnalystJoe BloggsMarketingSales

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]2[/TD]
[TD="align: center"]Unique ID[/TD]
[TD="align: center"]Project Role Name[/TD]
[TD="align: center"]Full Name[/TD]
[TD="align: center"]Division[/TD]
[TD="align: center"]Sub Division[/TD]
[TD="align: center"]Status[/TD]
[TD="align: center"]Start Date[/TD]
[TD="align: center"] End Date[/TD]

[TD="align: center"]3[/TD]
[TD="align: center"]1.0[/TD]

[TD="align: center"]Active[/TD]
[TD="bgcolor: #FFFF00, align: right"]1-Nov-13[/TD]
[TD="bgcolor: #FFFF00, align: right"]29-Sep-14[/TD]

[TD="align: center"]4[/TD]
[TD="align: center"]649.0[/TD]

[TD="align: center"]Active[/TD]
[TD="bgcolor: #FFFF00, align: right"]29-Jun-13[/TD]
[TD="bgcolor: #FFFF00, align: right"]4-Nov-14[/TD]

[TD="align: center"]5[/TD]
[TD="align: center"]453.0[/TD]

[TD="align: center"]Active[/TD]
[TD="bgcolor: #FFFF00, align: right"]26-Jul-13[/TD]
[TD="bgcolor: #FFFF00, align: right"]1-Feb-14[/TD]

[TD="align: center"]6[/TD]
[TD="align: center"]33.0[/TD]
[TD="align: center"]Manager[/TD]
[TD="bgcolor: #FFFFFF"]TBC[/TD]
[TD="bgcolor: #FFFFFF"]Merchandising[/TD]
[TD="bgcolor: #FFFFFF"]Shop Retail[/TD]
[TD="bgcolor: #FFFFFF, align: center"]Searching[/TD]
[TD="bgcolor: #FFFF00, align: right"]22-Nov-13[/TD]
[TD="bgcolor: #FFFF00, align: right"]26-Apr-14[/TD]

[TD="align: center"]7[/TD]
[TD="align: center"]5432.0[/TD]
[TD="align: center"]Finance Analyst[/TD]
[TD="bgcolor: #FFFFFF"]TBC[/TD]
[TD="bgcolor: #FFFFFF"]Merchandising[/TD]
[TD="bgcolor: #FFFFFF"]Shop Retail[/TD]
[TD="bgcolor: #FFFFFF, align: center"]Searching[/TD]
[TD="bgcolor: #FFFF00, align: right"]28-Nov-13[/TD]
[TD="bgcolor: #FFFF00, align: right"]1-Apr-15[/TD]

[TD="align: center"]8[/TD]
[TD="bgcolor: #66FFFF, align: center"]342.0[/TD]
[TD="bgcolor: #66FFFF, align: center"]Offshore HR[/TD]
[TD="bgcolor: #66FFFF"]TBC[/TD]
[TD="bgcolor: #66FFFF"]Logistics[/TD]
[TD="bgcolor: #66FFFF"]Transport[/TD]
[TD="bgcolor: #66FFFF, align: center"]Searching[/TD]
[TD="bgcolor: #66FFFF, align: right"]1-Jan-14[/TD]
[TD="bgcolor: #66FFFF, align: right"]13-Feb-15[/TD]

[TD="align: center"]9[/TD]
[TD="align: center"]3333.0[/TD]
[TD="align: center"]Data Analyser[/TD]
[TD="bgcolor: #FFFFFF"]TBC[/TD]
[TD="bgcolor: #FFFFFF"]Legal[/TD]
[TD="bgcolor: #FFFFFF"]Contracts[/TD]
[TD="bgcolor: #FFFFFF, align: center"]Searching[/TD]
[TD="bgcolor: #FFFF00, align: right"]4-Nov-13[/TD]
[TD="bgcolor: #FFFF00, align: right"]13-Sep-15[/TD]

[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

Hi Hiker

yes this is exaclty what i need - blue row as well! how would I be able to access the macro?

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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