Using DateAdd Function with cell values

  • Thread starter Thread starter loren.pottinger
  • Start date Start date
L

loren.pottinger

Both F7 and H7 contain a date yet this sub does not execute the
statements after Then.................Please help.

Sub GetAmOrDep()

Dim TestDate As Date
TestDate = DateAdd("m", Range("F7").Value, Range("H7").Value)

If TestDate < Range("I7").Value Then
Range("K7").Select
Selection.Copy
Range("M7").Select
ActiveSheet.Paste
End If
End Sub
 
see response in public.excel

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Thanks Bob. F7 does contain a number. Could it be because I am using
cell values?
 
loren.pottinger said:
Both F7 and H7 contain a date yet this sub does not execute the
statements after Then.................Please help.

Sub GetAmOrDep()

Dim TestDate As Date
TestDate = DateAdd("m", Range("F7").Value, Range("H7").Value)

If TestDate < Range("I7").Value Then
Range("K7").Select
Selection.Copy
Range("M7").Select
ActiveSheet.Paste
End If
End Sub


Hi Loren,

from msdn
(http://msdn.microsoft.com/library/d...html/f0ff19c4-0a74-44ca-867f-4739a814a88d.asp):

[cit]

DateAdd(interval, number, date)

Arguments

interval
Required. String expression that is the interval you want to add. See
Settings section for values.

number
Required. Numeric expression that is the number of interval you want to
add. The numeric expression can either be positive, for dates in the future,
or negative, for dates in the past.

date

Required. Variant or literal representing the date to which interval is
added.



Settings

The interval argument can have the following values:

Setting Description
yyyy
Year

q
Quarter

m
Month

y
Day of year

d
Day

w
Weekday

ww
Week of year

h
Hour

n
Minute

s
Second



[end cit]

This means that you cannot have dates in F7 and H7, but you need a number
(of month in your case, cause you used interval = "m") in F7 and a date in
H7.

--
Hope I helped you.

Thanks in advance for your feedback.

Ciao

Franz Verga from Italy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top