Number Of Days In Month

mattd4385

New Member
Joined
Nov 15, 2010
Messages
42
How do i set up a varable (X or whatever) as the number of days in the current month?

Ex. Today is 3-28-11 so... x = 31
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
This should give you what you're looking for:

Code:
dim x as long

x = Day(DateSerial(Year(Date), Month(Now()) + 1, 1) - 1)

hth
 
Upvote 0
There may be neater ways than this, but . . .
If the date is in A1
Code:
=DATE(YEAR(A1),MONTH(A1)+1,1)-DATE(YEAR(A1),MONTH(A1),1)

Edit to add, by the way, mine is obviously a formula solution, not VBA like Foo Man Chu's.
 
Upvote 0
Slightly shorter:
x = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
:)
 
Upvote 0
Or...

=DAY(EOMONTH(A1,0))

If you're using Excel 2003, you'll need to tick the analysis toolpak box under Tools, Addins.
 
Upvote 0
How do i set up a varable (X or whatever) as the number of days in the current month?

Ex. Today is 3-28-11 so... x = 31
One way...

=DAY(EOMONTH(NOW(),0))

Note that the EOMONTH function requires the Analysis ToolPak add-in be
installed if you're using a version of Excel prior to Excel 2007. If you enter the formula and get a #NAME? error look in Excel help for the EOMONTH function. It'll tell you how to fix the problem.
 
Upvote 0
Just for fun :)

If you have a date in A1 this formula will give you the number of days in that month

=42-DAY((A1-DAY(A1)+42))
 
Upvote 0
Barry,
There's something wrong with your brain. ;)
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,741
Members
452,940
Latest member
rootytrip

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