ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert Row and calculate difference between two dates (https://www.excelbanter.com/excel-programming/434460-insert-row-calculate-difference-between-two-dates.html)

Jazz

Insert Row and calculate difference between two dates
 
I am looking to insert a row above each row with contents starting in Row 2.
Minus the date in Column C for each row with contents from todays date and
put the difference in Column A the empty row above. Here is what I am
starting with.

Dim lngRow As Long, blnInsert As Boolean
lngRow = 2
Do While lngRow <= Cells(Rows.Count, "G").End(xlUp).Row
blnInsert = Not blnInsert
If blnInsert Then
Rows(lngRow).Insert
Range("A" & lngRow) = Date - Range("G" & lngRow + 1)
End If
lngRow = lngRow + 1
Loop

I would like to add to this code so that it will also minus the date in
Column H for each row with contents from todays date and put the difference
in Column D the empty row above. Can you help?


joel

Insert Row and calculate difference between two dates
 
just add one line

from
Range("A" & lngRow) = Date - Range("G" & lngRow + 1)

to

Range("A" & lngRow) = Date - Range("G" & lngRow + 1)
Range("D" & lngRow) = Date - Range("H" & lngRow + 1)

"Jazz" wrote:

I am looking to insert a row above each row with contents starting in Row 2.
Minus the date in Column C for each row with contents from todays date and
put the difference in Column A the empty row above. Here is what I am
starting with.

Dim lngRow As Long, blnInsert As Boolean
lngRow = 2
Do While lngRow <= Cells(Rows.Count, "G").End(xlUp).Row
blnInsert = Not blnInsert
If blnInsert Then
Rows(lngRow).Insert
Range("A" & lngRow) = Date - Range("G" & lngRow + 1)
End If
lngRow = lngRow + 1
Loop

I would like to add to this code so that it will also minus the date in
Column H for each row with contents from todays date and put the difference
in Column D the empty row above. Can you help?


Jazz

Insert Row and calculate difference between two dates
 
Wow. Great. This is what I was looking for. Thank you.

"Joel" wrote:

just add one line

from
Range("A" & lngRow) = Date - Range("G" & lngRow + 1)

to

Range("A" & lngRow) = Date - Range("G" & lngRow + 1)
Range("D" & lngRow) = Date - Range("H" & lngRow + 1)

"Jazz" wrote:

I am looking to insert a row above each row with contents starting in Row 2.
Minus the date in Column C for each row with contents from todays date and
put the difference in Column A the empty row above. Here is what I am
starting with.

Dim lngRow As Long, blnInsert As Boolean
lngRow = 2
Do While lngRow <= Cells(Rows.Count, "G").End(xlUp).Row
blnInsert = Not blnInsert
If blnInsert Then
Rows(lngRow).Insert
Range("A" & lngRow) = Date - Range("G" & lngRow + 1)
End If
lngRow = lngRow + 1
Loop

I would like to add to this code so that it will also minus the date in
Column H for each row with contents from todays date and put the difference
in Column D the empty row above. Can you help?



All times are GMT +1. The time now is 07:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com