Given that I have a column of values in the format
01.2020
12.2021
3.2019
02.2020
etc.
over a million rows or so, I want a VBA function to find the maximum value of the digits to the left of the period.
Something like
Option Explicit
Sub test()
Dim r As Range, c As Range
Dim max As Long, current As Long
Dim s As String
With ?r_2020
Set r = .Range(.Range("D2"), .Range("D" & .Rows.Count).End(xlUp))
End With
For Each c In r
current = CLng(Left(c, InStr(1, c, ".", vbBinaryCompare) - 1))
If current > max Then max = current
Next c
Debug.Print max
End Sub
works, but I feel like there ought to be a simpler solution.
Can someone please give some input on whether they can find a simpler solution?
question from:
https://stackoverflow.com/questions/66064144/max-of-substring-in-column 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…