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

Looping through list of dates to display datediff

$
0
0

I am trying to create a macro that as well as many other things will loop through the dates in column and, compare it to the "due date" and show the amount of dates that is left

Unfortunately the macro that I wrote doesn't give the desired outcome and gives me some huge number instead.

my code for that part so far is:

Sub calcDays()

Dim dueDate As Date
Dim macroLastRow As Long
Dim macroWs As Worksheet


Set macroWs = ThisWorkbook.Worksheets("Macro")

macroLastRow = macroWs.Range("A"& Rows.Count).End(xlUp).Row
dueDate = Range("B1").Value


For i = 2 To macroLastRow

Cells(i, 2).Value = DateDiff("d", i, dueDate)

Next i



End Sub

This is what I get after I run the macro:

enter image description here

I hope that you guys will be able to advise! Thanks a mil in advance!


Viewing all articles
Browse latest Browse all 88835

Trending Articles



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