?
Solved

VBA to increase cell value by 1

Posted on 2009-12-31
5
Medium Priority
?
409 Views
Last Modified: 2012-08-14
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
Comment
Question by:stmoritz
  • 3
5 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26153582
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
 
LVL 20

Expert Comment

by:Ardhendu Sarangi
ID: 26153595
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
 
LVL 20

Expert Comment

by:Ardhendu Sarangi
ID: 26153604
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
 
LVL 20

Accepted Solution

by:
Ardhendu Sarangi earned 200 total points
ID: 26153614
Sub ChangeNAVdateOneDayForward()

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

End Sub
0
 

Author Closing Comment

by:stmoritz
ID: 31671576
Perfect! Short, efficient, great! Thanks! And a healthy and happy 2010 to you!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question