Link to home
Start Free TrialLog in
Avatar of stmoritz
stmoritz

asked on

VBA to increase cell value by 1

what am I doing wrong in this completely beginner easy code? it should increase the current value in cell A1 (named "CalcDate") by 1.
Sub ChangeNAVdateOneDayForward()

Dim OldDate As Integer
Dim NewDate As Integer

OldDate = Range("CalcDate").Value
NewDate = OldDate + 1
Range("CalcDate").Value = NewDate

End Sub

Open in new window

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello stmoritz,

It should work ok ... I presume the cell is a date, (any number will do though and that macros are enabled?  To double check try adding a stop as the first line and see if it is triggered

Regards,

chris_bottomley
Hi,

The syntax in line 6 is incorrect. The range is referencing an incorrect value. What value does CALCDATE stands for?

you can do this in a easier way as shown below...

assuming ur date is in cell B2 use the following code...

- Ardhendu
Sub ChangeNAVdateOneDayForward()

' Assuming your date value is in Cell B2

Range("B2").Value = Range("B2").Value + 1

End Sub

Open in new window

Sorry I didn't see the A1 reference in your question.

use the following code..

Sub ChangeNAVdateOneDayForward()

Range("A1").Value = Range("A1").Value + 1

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ardhendu Sarangi
Ardhendu Sarangi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stmoritz
stmoritz

ASKER

Perfect! Short, efficient, great! Thanks! And a healthy and happy 2010 to you!