• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

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

0
stmoritz
Asked:
stmoritz
  • 3
1 Solution
 
Chris BottomleySoftware Quality Lead EngineerCommented:
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
0
 
Ardhendu SarangiSr. Project ManagerCommented:
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

0
 
Ardhendu SarangiSr. Project ManagerCommented:
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

0
 
Ardhendu SarangiSr. Project ManagerCommented:
Sub ChangeNAVdateOneDayForward()

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

End Sub
0
 
stmoritzAuthor Commented:
Perfect! Short, efficient, great! Thanks! And a healthy and happy 2010 to you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now