number of days between dates in macro

xelhelp

New Member
Joined
Mar 6, 2011
Messages
28
i have three dynamic columns that have dates in them.
there are dates in column E, I, and J starting at row 5 and going down X number of rows...X because i have an external feed which updates and it results in column E, I and J going down different numbers of rows every time it updates....but each column will have data going down to the same row for each update.... i would like to populate cells M5:MX with the difference in days between colE - colI and cells N5:NX with the difference in days between colJ - colE

im getting a "Run-time error 13" "Type mismatch"

im new to vba so im not sure how to fix this error

the update also populates data in column B, from cell B5:BX, it will also go down the same number of rows as column E, I, and J

the variable RowCount determines how many rows starting at row 5 have data in them....

this is in worksheet2 so im using the worksheet change event handler...
here is what the code looks like

any input will be greatly appreciated


Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim RowCount As Double
RowCount = Application.WorksheetFunction.CountA(Range("B5:B200"))


Dim Counter2 As Double
Counter = 0

Application.EnableEvents = False

Do Until Counter2 > RowCount - 1

Range("M5").Offset(Counter2, 0) = (Range("M5").Offset(Counter2, -8)) - (Range("M5").Offset(Counter2, -4))
Range("N5").Offset(Counter2, 0) = (Range("N5").Offset(Counter2, -4)) - (Range("N5").Offset(Counter2, -9))

Counter2 = Counter2 + 1
Loop

Application.EnableEvents = True

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,215,641
Messages
6,125,983
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top