-
Jul 7th, 2020, 02:36 AM
#1
Thread Starter
Member
[RESOLVED] [Excel VBA] Search a list for Max alphabetic
Hey guys,
I'm looking for a VBA function to search for maximum in a column list including numbers and alphabets. But with specific criteria. Please see the below example:
I need to find the max FY19-XXX value in column A below (result should be FY19-247). However, better not to use a loop as the list includes more than 10k data
Data in Column A:
FY18-286
FY17-136
FY18-288
FY18-289
FY18-286
FY19-235
FY19-229
FY19-247
FY19-241
FY19-242
FY20-007
FY20-001
FY20-002
FY20-003
FY20-004
-
Jul 7th, 2020, 03:25 AM
#2
Re: [Excel VBA] Search a list for Max alphabetic
My money would be on the MAXIFS-Function.
https://exceljet.net/excel-functions...axifs-function
No idea how to use it.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jul 7th, 2020, 04:22 AM
#3
Re: [Excel VBA] Search a list for Max alphabetic
this custom function should do as you want, uses excel find method, it does contain a loop, but lees than 1000 iterations, seems to be quick enough
if a max possible value is known then the loop can be reduced, i used 999 as max possible 3 digit value
Code:
Function maxl(r As Range, fy As String)
Dim n As Integer, fnd As Range
For n = 999 To 1 Step -1
Set fnd = r.Find(fy & "-" & n)
If Not fnd Is Nothing Then Exit For
Next
maxl = fnd
End Function
call like =maxl(A1:A15,"fy19")change range and year entry to suit, of course invalid values will take longer and or create error
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 7th, 2020, 04:41 AM
#4
Thread Starter
Member
Re: [Excel VBA] Search a list for Max alphabetic
Thanks a lot westconn1 .. that works fine
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|