I'M STUCK!!! Trying to add dates in VBA.

chouston

Board Regular
Joined
Apr 24, 2002
Messages
68
Can anyone tell me why this won't work???

--
Dim endcycle As Date
Dim newstartcycle As Date

newstartcycle = CDate(InputBox("Enter beginning date of billing cycle."))

endcycle = DateAdd(m, 1, newstartcycle)
--

thanks in advance to whomever solves this!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
additionally, how can I use VBA to return a date that is the 1st of the next month?

e.g. 3/15 --> 4/1
8/15 --> 9/1

etc.

Thanks again if you can answer this
 
Upvote 0
Add quotes around the 'm' in the DateAdd

Change:
endcycle = DateAdd(m, 1, newstartcycle)
to
endcycle = DateAdd("m", 1, newstartcycle)
 
Upvote 0
On 2002-05-06 16:17, chouston wrote:
additionally, how can I use VBA to return a date that is the 1st of the next month?

e.g. 3/15 --> 4/1
8/15 --> 9/1

etc.

Thanks again if you can answer this

One way:

DateSerial(Year(endcycle), Month(endcycle) + 1, 1)

Another is to use the EOMONTH function, but you have to set references to the Analysis ToolPak to call the function.
 
Upvote 0
THANKS!

I ended up cheating on the second part though:
--
newstartcycle = InputBox("Enter beginning date of billing cycle.")

endcycle = DateAdd("m", 1, newstartcycle)
nextdate = DateAdd("m", 1, endcycle)
duedate = DateAdd("d", -14, nextdate)
--
it's not fancy, but it works, Thanks again.
 
Upvote 0
You may want to validate the date, i.e., application.inputbox....type:=1, at the very least, you'll get a number.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top