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
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
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
Sorry I didn't see the A1 reference in your question.
use the following code..
use the following code..
Sub ChangeNAVdateOneDayForward()
Range("A1").Value = Range("A1").Value + 1
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! Short, efficient, great! Thanks! And a healthy and happy 2010 to you!
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