Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

F = Date(YEAR(F)+1,MONTH(F),DAY(F))) will not work

Status
Not open for further replies.

mwheads

Programmer
Apr 24, 2004
38
ZA
Hi Everyone

I cannot get Date(YEAR(F)+1,MONTH(F),DAY(F))) to work in VBA but it works fine as a formula on a sheet.

I am trying to use it in VBA:

Sub RollOver()
If Range("E1") = 12 Then

Dim F As Object

For Each F In Range("B1:B12")

F = Date(YEAR(F)+1,MONTH(F),DAY(F)))

Next F

End If
End Sub


but I always get an error....Compile Error, Expected:)

as far as I can see there are no "(" missing and no matter how many I add or take away, it is not working for me.

does anybody know where the problem is.

Regards
 
Hi mwheads,

Date used like that is a WORKSHEET Function. The equivalent VBA Function is DateSerial. To make it update cells, I think you'll also need to add the Value (as below).

Code:
[blue]F[b].Value[/b] = Date[b]Serial[/b](YEAR(F)+1,MONTH(F),DAY(F)))[/blue]



Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thanks Tony, that works great, easy when you know how!

Kind Regards,
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top