Hi Larry,

Try Using this formula instead.

=DATE(B4,B3,B2)-DATE(D4,D3,D2)

Cheers,
Lohith

On Dec 5, 12:51 am, larry <[EMAIL PROTECTED]> wrote:
> I am trying to creat a code for caculating the number of days between
> two dates. N=A-N causes a type mismacth run time error. Also looking
> for any other improvements. Nested if may need to be cleared up.
>
> Thanks for any help.
>
> Option Explicit
> Public M1 As Integer, M2 As Integer, D1 As Integer, D2 As Integer, Y1
> As Variant, Y2 As Variant
> Public N As Integer, A As Integer
> Sub DayDelta()
> M1 = Cells(2, 2).Value
> D1 = Cells(3, 2).Value
> Y1 = Cells(4, 2).Value
> M2 = Cells(2, 4).Value
> D2 = Cells(3, 4).Value
> Y2 = Cells(4, 4).Value
> Call Daycalc(M1, D1, Y1, A)
> N = A
> Call Daycalc(M2, D2, Y2, A)
> N = A - N
> N = Cells(3, 5).Value
> End Sub
> Sub Daycalc(M, D, Y, A)
> Public M As Integer, D As Integer, Y As Variant, A As Integer
>
> Select Case M
> Case 1
> A = 0
> Case 2
> A = 31
> Case 3
> A = 59
> Case 4
> A = 90
> Case 5
> A = 120
> Case 6
> A = 151
> Case 7
> A = 181
> Case 8
> A = 212
> Case 9
> A = 243
> Case 10
> A = 273
> Case 11
> A = 304
> Case 12
> A = 334
> End Select
> A = A + Y * 365 + Int(Y / 4) + D + 1 - Int(Y / 100) + Int(Y / 400)
> If Int(Y / 4) = Y / 4 Then
>     If Y / 400 = Int(Y / 400) Then
>         If M < 3 Then
>         A = A - 1
>         End If
>     Else
>     If Y / 100 <> Int(Y / 100) Then
>     If M < 3 Then
>         A = A - 1
>         End If
> End If
> End Sub

--~--~---------~--~----~------------~-------~--~----~
Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To post to this group, send email to excel-macros@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/excel-macros?hl=en

Visit & Join Our Orkut Community at 
http://www.orkut.com/Community.aspx?cmm=22913620

Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To Learn VBA Macros Please visit http://www.vbamacros.blogspot.com

To see the Daily Excel Tips, Go to:
http://exceldailytip.blogspot.com
-~----------~----~----~----~------~----~------~--~---

Reply via email to