(Solved) – Extracting data between two given dates

  • by
(solved)-–-extracting-data-between-two-given-dates

I have a table in excel having eight columns which includes year, date of deposit and total fees.

Now, if date of deposit is between two given dates and it pertains to year 2019-20 then I am trying to extract value from corresponding fee column. I am trying to get total fees deposited between two given dates for a particular year. But I am not getting desired result. Kindly help.

I am using If and Else statement and For Each loop.

Sub Macro12()
    Dim Cell As Range
    Dim Cell2 As Range

    For Each Cell In Range("D2:D25")
        ' If (Cell.Value >= DateValue("1 / 5 / 2019")) And (Cell.Value <= DateValue("30 / 4 / 2020")) Then
        If (Cell.Value >= 43586) And (Cell.Value <= 43951) Then
            For Each Cell2 In Range("C2:C25")
                If Cell2.Value = "2020-21" Then
                    Range("I3").Value = Cell2.Value
                    Range("J3").Value = Range("J3").Value   Cell2.Offset(0, 5).Value
                Else
                    Range("I4").Value = "other years"
                    Range("J4").Value = Range("J4").Value   Cell2.Offset(0, 5).Value
                End If
            Next Cell2
            ' ElseIf (Cell.Value >= DateValue("1 / 5 / 2021")) And (Cell.Value <= DateValue("30 / 4 / 2022")) Then
        ElseIf (Cell.Value >= 43599) And (Cell.Value <= 43599) Then
            Range("M3").Value = "step 1 clear"
        End If
    Next Cell
End Sub

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *