• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Date wise code

ashish mehra

Active Member
Hi,

Please check attached file, output is mentioned.

Regards,
AM
 

Attachments

  • Date wise Code.xlsx
    9.1 KB · Views: 5
Last edited:
You have missed a interval in output

KCRJ151714 25-Mar-16

Check this..

Code:
Sub test()
Dim i As Integer, r As Range, x As Integer, d As Integer

i = 4
For Each r In [b4:b7]
    d = 0: x = 0
        Do While x < r.Offset(, 2) - r.Offset(, 1) + 1
            Cells(i, 10) = r
            Cells(i, 11) = r.Offset(, 1) + d
            d = d + 1: i = i + 1: x = x + 1
        Loop
Next

End Sub
 
You have missed a interval in output

KCRJ151714 25-Mar-16

Check this..

Code:
Sub test()
Dim i As Integer, r As Range, x As Integer, d As Integer

i = 4
For Each r In [b4:b7]
    d = 0: x = 0
        Do While x < r.Offset(, 2) - r.Offset(, 1) + 1
            Cells(i, 10) = r
            Cells(i, 11) = r.Offset(, 1) + d
            d = d + 1: i = i + 1: x = x + 1
        Loop
Next

End Sub
Yes I missed an interval.

Thanks for VBA solution, can this be achieved with formula.

Regards
 
Hi Ashish ,

1. I have used a helper column , column E.

In E4 , enter the formula =D4-C4+1

Copy down.

2. I have put in the outputs in columns J and K. The formulae are different for the first row and thereafter.

In J4 , enter the formula =B4

In K4 , enter the formula =C4

3. In the second row , enter the following formulae :

J5

=IFERROR(IF(INDEX($E$4:$E$7,MATCH(J4,$B$4:$B$7,0))>COUNTIF(J$4:J4,J4),J4,INDEX($B$4:$B$7,MATCH(J4,$B$4:$B$7,0)+1)),"")

K5

=IF(J5="","",IF(J5<>J4,INDEX($C$4:$C$7,MATCH(J5,$B$4:$B$7,0)),K4+1))

Copy down as far as required.

Narayan
 
Back
Top