Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

Extracting data between two given dates

$
0
0

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


Viewing all articles
Browse latest Browse all 88854


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>