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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,216,025
Messages
6,128,348
Members
449,443
Latest member
Chrissy_M

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