Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Subtracting Dates VBA

Hi,

I want to subtract two dates 'YYYYY-MM-DD' but by doing in VBA and pointing
to their respective cells and dump the result in another cell.

For example, I am working on this experiment :

Quote:
Sub datescalcul()
Dim Baux As Double
Baux = Application.DATEDIF(Worksheets("Formulaire").Range ("I16").Value,
Worksheets("Formulaire").Range("J16").Value, "m") / 12
sheets("Formulaire").Range("K16").Value = Baux
End Sub
But it does not work. Maye it is that dateDif Excel function cannot be
converted in VBA function?
Thx!

JJD

--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Subtracting Dates VBA

"does not work" does not give much information.
But in VBA, it is DATEDIFF (2 F's)

Niek Otten
"Jean-Jerome Doucet via OfficeKB.com" wrote in
message ...
Hi,

I want to subtract two dates 'YYYYY-MM-DD' but by doing in VBA and
pointing
to their respective cells and dump the result in another cell.

For example, I am working on this experiment :

Quote:
Sub datescalcul()
Dim Baux As Double
Baux = Application.DATEDIF(Worksheets("Formulaire").Range ("I16").Value,
Worksheets("Formulaire").Range("J16").Value, "m") / 12
sheets("Formulaire").Range("K16").Value = Baux
End Sub

But it does not work. Maye it is that dateDif Excel function cannot be
converted in VBA function?
Thx!

JJD

--
Message posted via http://www.officekb.com



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Subtracting Dates VBA

So that is without "Application."

"Niek Otten" wrote in message
...
"does not work" does not give much information.
But in VBA, it is DATEDIFF (2 F's)

Niek Otten
"Jean-Jerome Doucet via OfficeKB.com" wrote in
message ...
Hi,

I want to subtract two dates 'YYYYY-MM-DD' but by doing in VBA and
pointing
to their respective cells and dump the result in another cell.

For example, I am working on this experiment :

Quote:
Sub datescalcul()
Dim Baux As Double
Baux = Application.DATEDIF(Worksheets("Formulaire").Range ("I16").Value,
Worksheets("Formulaire").Range("J16").Value, "m") / 12
sheets("Formulaire").Range("K16").Value = Baux
End Sub

But it does not work. Maye it is that dateDif Excel function cannot be
converted in VBA function?
Thx!

JJD

--
Message posted via http://www.officekb.com





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Subtracting Dates VBA

You are right, my apologies for the lack of details.

I forgot to mention that the error is on my subtraction. It says property or
method not managed by this object. And I want to return a numer of years and
have decimal or where we are in the last years (e.g. 3 and a half year 3,50).

Here's the way it is supposed to work :
Oh and it is J16 - I16 (upper date - lower date).

Werner

--
Message posted via http://www.officekb.com
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Subtracting Dates VBA

Ops wrong name (I use Werner as a nickname on other forums but I use my real
name on this one.)

Jean-Jérôme Doucet

--
Message posted via http://www.officekb.com


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Subtracting Dates VBA

It is also a different order

With Worksheets("Formulaire")
Baux = DateDiff("m", .Range("I16").Value, .Range("J16").Value) / 12
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jean-Jerome Doucet via OfficeKB.com" wrote in
message ...
Hi,

I want to subtract two dates 'YYYYY-MM-DD' but by doing in VBA and

pointing
to their respective cells and dump the result in another cell.

For example, I am working on this experiment :

Quote:
Sub datescalcul()
Dim Baux As Double
Baux = Application.DATEDIF(Worksheets("Formulaire").Range ("I16").Value,
Worksheets("Formulaire").Range("J16").Value, "m") / 12
sheets("Formulaire").Range("K16").Value = Baux
End Sub

But it does not work. Maye it is that dateDif Excel function cannot be
converted in VBA function?
Thx!

JJD

--
Message posted via http://www.officekb.com



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Subtracting Dates VBA

Thank you a lot Bob!!

I adjusted a bit the code for my needs and i works perfectly!

Have a good day!

Werner

Quote:
Sub datescalcul()

Dim Baux As Double
Dim I As Long

Let lstRw = Sheets("Formulaire").Range("a65536").End(xlUp).Row

For I = 16 To lstRw
With Worksheets("Formulaire")
Baux = DateDiff("m", Sheets("Formulaire").Range("I" & I).Value, Sheets
("Formulaire").Range("J" & I).Value) / 12
Sheets("Formulaire").Range("K" & I).Value = Baux
End With

Next I


End Sub
--
Message posted via http://www.officekb.com
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtracting Dates Dilly Excel Discussion (Misc queries) 10 January 28th 08 04:00 PM
Subtracting Dates jaxstraww Excel Discussion (Misc queries) 0 March 28th 07 01:58 AM
Subtracting Dates jaxstraww Excel Discussion (Misc queries) 0 March 28th 07 01:56 AM
Subtracting dates toot033 Excel Discussion (Misc queries) 3 July 17th 06 09:03 PM
Subtracting Dates sam Excel Discussion (Misc queries) 3 March 2nd 06 12:47 PM


All times are GMT +1. The time now is 11:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"