<<Convert Excel Spreadsheets to Web Pages | Trading Software That Operates Within Excel | Convert Excel, Access & Other Databases | Merge Excel Files>> |
---|
Back to: Excel VBA. Got any Excel/VBA Questions? Free Excel Help
Number of Specified Days in a Specified Month. See Also:Determine nth Weekday of a Specified Date ||Return Last Chosen Day of Given Month
The function below can be used to determine how may days (e.g Mondays etc) there are in any specified month. For example
=HowManyDaysInMonth("1/12/03","wed")
will return 5 as there are five Wednesdays in the month of December in 2003
=HowManyDaysInMonth("1/12/03","thu")
will return 4 as there are four Thursdays in the month of December in 2003
To be able to use this custom function in a Workbook, you must first place the code below into a standard module.
'The Code
Function HowManyDaysInMonth(FullDateAs String, sDay As String) As IntegerDim i As IntegerDim iDay As Integer, iMatchDay As IntegerDim iDaysInMonth As IntegerDim FullDateNew As Date iMatchDay = Weekday(FullDate) Select Case UCase(sDay) Case "SUN" iDay = 1 Case "MON" iDay = 2 Case "TUE"quot; iDay = 3 Case "WED" iDay = 4 Case "THU" iDay = 5 Case "FRI" iDay = 6 Case "SAT" iDay = 7 End Select iDaysInMonth = Day(DateAdd("d", -1, DateSerial _ (Year(FullDate), Month(FullDate) + 1, 1))) FullDateNew = DateSerial(Year(FullDate), Month(FullDate), iDaysInMonth) For i = iDaysInMonth - 1 To 0 Step -1 If Weekday(FullDateNew - i) = iDay Then HowManyDaysInMonth = HowManyDaysInMonth + 1 End If Next iEnd Function
Now simply enter the function into any cell as shown above.
Excel Dashboard Reports & Excel Dashboard Charts 50% Off Become an ExcelUser Affiliate & Earn Money
Special! Free Choice of Complete Excel Training Course OR Excel Add-ins Collection on all purchases totaling over $64.00. ALLpurchases totaling over $150.00 gets you BOTH! Purchases MUST be made via this site. Send payment proof to [email protected] 31 days after purchase date.
Instant Download and Money Back Guarantee on Most Software
Excel Trader PackageTechnical Analysis in Excel With $139.00 of FREE software!
Microsoft � and Microsoft Excel � are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft
Some of our more popular products are below...
Convert Excel Spreadsheets To Webpages | Trading In Excel | Construction Estimators | Finance Templates & Add-ins Bundle | Code-VBA | Smart-VBA | Print-VBA | Excel Data Manipulation & Analysis | Convert MS Office Applications To...... | Analyzer Excel | Downloader Excel | MSSQL Migration Toolkit | Monte Carlo Add-in | Excel Costing Templates