Re: Compare Version Number Strings
blablubbb Thank You. Just found a spelling error in Version1Array and changed the Application.Min function to standard vba:
Code
Public Function VersionCompare(Version1 As String, Version2 As String) As Integer 'returns 1 if Version 1 is newer
'returns -1 if version 1 is older
'returns 0 if both versions are the same
Dim i As Integer
Dim Version1Array() As String
Dim Version2Array() As String
Version1Array = Split(Version1, ".")
Version2Array = Split(Version2, ".")
Dim k As Integer
k = UBound(Version1Array)
If UBound(Version2Array) < k Then k = UBound(Version2Array)
For i = 0 To k
If Version1Array(i) > Version2Array(i) Then
VersionCompare = 1
Exit For
ElseIf Version1Array(i) < Version2Array(i) Then
VersionCompare = -1
Exit For
Else
If UBound(Version1Array) = UBound(Version2Array) Then
VersionCompare = 0
ElseIf UBound(Version1Array) > UBound(Version2Array) Then
VersionCompare = 1
Else
VersionCompare = -1
End If
End If
Next i
End Function
Display More