Days in next month

austinpcherry

New Member
Joined
Feb 26, 2014
Messages
36
I would like to create a button to dynamically make a sheet for each day of the next month and rename it to the day.
I am having trouble obtaining an accurate number for the days in next month. I can't really move forward until this variable is defined. I am sure it is something simple that I am just overlooking.
I appreciate the help in advance.
Code:
Sub NewMonth()
Dim nextMonth As String
Dim daysInNextMonth As Double

nextMonth = Month(Now) + 1

Application.ScreenUpdating = False

Workbooks.Add
ActiveWorkbook.SaveAs "C:\Group Documents\TRUCK LOG\TRUCK LOG\ SERETEAN TRUCK LOG " & MonthName(nextMonth, True) & " " & Year(Now), xlOpenXMLWorkbookMacroEnabled

Application.DisplayAlerts = False
Worksheets("Sheet2").Delete
Worksheets("Sheet3").Delete
Application.DisplayAlerts = True

[COLOR=#ff0000]daysInNextMonth= ??????????[/COLOR]

Worksheets.Add Count:=daysInNextMonth - 1

'........... More to follow .........

Application.ScreenUpdating =True
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi,
Try:

Code:
Dim NextMonth As Integer, DaysInNextMonth As Integer


NextMonth = Month(Now) + 1


DaysInNextMonth = Day(DateSerial(Year(Date), NextMonth + 1, 1) - 1)

Dave
 
Upvote 0
How about:

Code:
Dim DaysInNextMonth As Integer


DaysInNextMonth = Day(DateSerial(Year(Now), Month(Now) + 2, 0))

igold
 
Upvote 0
Just checked back. Thank you guys. I was still working on it. Anyone see any reason that this won't work?
Code:
daysInNextMonth = Day(CDate(Application.WorksheetFunction.EoMonth(nextMonth, 0)))
 
Upvote 0
Hi,

I poked around a bit and would seem that EoMonth does not play nice with VBA. I saw a lot of workarounds but I think that both dmt32 and myself gave you the best approach (imho).

igold
 
Upvote 0
Try :-
Code:
DaysInNextMonth = Day(Application.WorksheetFunction.EoMonth(INT(Now()), 1))

hth
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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