Finding maximum day number in column

bukimi

Board Regular
Joined
Apr 12, 2017
Messages
105
Office Version
  1. 2019
Platform
  1. Windows
I have a column with dates. Usually it consists of dates only within one month, but very rarely it has also 1st day of the next month.
I need to find maximum (latest) day number to use it in many different places in my VBA code.

Currently it looks like this:
Code:
FindLastDay = Day(WorksheetFunction.Max(Worksheets("Sales").Columns(11)))

It works really fine, except for the fact that if all dates are from May and one date is 1st June, then "FindLastDay" will give me result 1 (as it takes latest day from all dates into consideration, which is 1st June as source).

How can I fix it to take highest number of day, regardless of month in the date?
Thank you in advance for your help!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
may be

FindLastDay = Max(WorksheetFunction.Day(Worksheets("Sales").Columns(11)))
 
Upvote 0
Sorry, doesn't work.

For your code it gives "Sub or Function not defined".

I tried adding WorksheetFunction. before Max, but then it gives error "Object doesn't support this property or method".
 
Upvote 0
How about
Code:
   With Range("L2", Range("L" & Rows.Count).End(xlUp))
      FindLastDay = Evaluate("=DAY(MAX(DAY(" & .Address & ")))")
   End With
 
Upvote 0
It works!
Now my code will work for all days, even 1st day of another month :)

Thank you!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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