I have a question on regard to calculating date difference in days, looping through a cell range. This is the code that I have come up with but it only calculates for the first record on the spreadsheet. Im totally missing the looping function to go through
each of the rows.
I have created a button on the spreadsheet that when clicked it references the below macro.
Please help.
Sub Test2()
' Select cell A2, *first line of data*.
Range("A2").Select
Dim ws As Worksheet
Dim date1 As Range
Dim date2 As Range
Dim x As String ' this is the dates calculation value
Dim destcell As Range 'destination cell
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
Set destcell = Worksheets("G0").Range("$AW2") 'initiate destination cell
Set date1 = Worksheets("G0").Range("$AB2") ' initiate cell range for first date to use for calculation
Set date2 = Worksheets("G0").Range("$A2") ' initiate cell range for second date to use for calculation
'For next here??
x = DateDiff("d", date1, date2) ' calculation to assign date difference in days to variable x
destcell.Value = x 'copy contents of variable into specified cell range
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
'Need to enter loop here
Loop
End Sub