Tweak existing code to get the desired output

motherindia

Board Regular
Joined
Oct 15, 2015
Messages
218
Hi Sir,

The following code plot the days between 2 dates into separate column. However, I need to get number of days between 2 dates monthwise;


IDS Date E Date
101/06/201715/07/2017
116/07/201712/08/2017
114/08/201730/08/2017
output should be
IDJun'17Jul'17Aug'17
1303130

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>




http://www.ozgrid.com/forum/showthread.php?t=197056&page=2&




sub test
Dim a, i As Long, ii As Long, w, DD, ub As Long
a = Cells(1).CurrentRegion.Value
With CreateObject("Scripting.Dictionary")
For i = 2 To UBound(a, 1)
If Not .exists(a(i, 1)) Then
Redim w(1 To 2)
For ii = 1 To 2
w(ii) = a(i, ii)
Next
.Item(a(i, 1)) = w
Else
w = .Item(a(i, 1))
End If
ub = UBound(w)
DD = DateDiff("d", a(i, 3), a(i, 4)) + 1
Redim Preserve w(1 To UBound(w) + DD)
For ii = ub + 1 To UBound(w)
w(ii) = a(i, 3) + ii - ub - 1
Next
.Item(a(i, 1)) = w
Next
For i = 0 To .Count - 1
Sheets("Sheet2").Select
Range("A1").Select

Cells(i + 1, "a").Resize(, UBound(.items()(i))) = .items()(i)
Next
End With


End sub

Regards,
motherindia
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,215,169
Messages
6,123,412
Members
449,098
Latest member
ArturS75

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