Find min in filtered range in VBA

QuestionBaker

Board Regular
Joined
Apr 12, 2019
Messages
106
Office Version
  1. 365
Platform
  1. Windows
I wish to prepare Gannt chart from a sheet where bunch of projects are listed.
I am unable to find oldest date after filtering the relevant project.

I've tried min (K3 to N1770) (data is there till row 1770) but it gives an answer as Sep 2016, so I know I am making a mistake.

How do I find min and max in a filtered range

my data looks as follows
1628252761269.png
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
How about adding an extra column to your data with
Excel Formula:
=SUBTOTAL(3,A2)
and drag down, change the A2 to reference a column that will have values on every row.
Then you can refer to that extra column in your formula. Are you trying to find the min date in a specific column or just the min date in all the columns?
 
Upvote 0
How about adding an extra column to your data with
Excel Formula:
=SUBTOTAL(3,A2)
and drag down, change the A2 to reference a column that will have values on every row.
Then you can refer to that extra column in your formula. Are you trying to find the min date in a specific column or just the min date in all the columns?
Thanks for the response, but would that work in VBA?
I forgot to mention it in my post but i included in in the title
 
Upvote 0
Yes it will. Can you answer my question?
 
Upvote 0
Ok, how about
VBA Code:
Sub QuestionBaker()
   msgbox Evaluate("min((K3:N1770)*(O3:O1770=1))")
End Sub
Change col O if needed to which ever col you have put the Subtotal formula in.
 
Upvote 0
T202108a.xlsm
AB
1
225-May-21
3StartCriteria
625-May-21B
1114-Jul-21B
1712-Sep-21B
18
19
2b
Cell Formulas
RangeFormula
A2A2=SUBTOTAL(105,Table1[Start])


T202108a.xlsm
KL
1
225-May-21
3StartCriteria
625-May-21B
1114-Jul-21B
1712-Sep-21B
18
2b
Cell Formulas
RangeFormula
K2K2=SUBTOTAL(105,K3:K17)
 
Last edited:
Upvote 0
Definitely over thought it, no need for the helper column you can just use
VBA Code:
Sub QuestionBaker()
   MsgBox Evaluate("subtotal(105,K3:N1770)")
End Sub
 
Upvote 0
Solution
Or

VBA Code:
Sub xTest()
    Dim lMinDate As Long
    
    lMinDate = Application.Aggregate(15, 5, Range("K3:N1770"), 1)
    MsgBox lMinDate
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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