If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Compare version numbers and return the highest value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-11, 18:14
suttungur suttungur is offline
Registered User
 
Join Date: Oct 2011
Posts: 1
Compare version numbers and return the highest value

I'm trying to compare version numbers of software applications and need to retrieve the highest value, in other words keep track what is the latest version at any given time sheet is updated. Each application has a single, dedicated row containing the version numbers in random order (it is also possible for some or all cells to contain the same version). Format of the version numbers:

1.0.0
1.0.1
1.1.0 << highest of the three

Can also be:
1.11.0 << lowest
1.2.0 << 2nd highest
2.00.0 << highest

Also:
11.22.33
11.3.1 << highest

I have been trying to achieve this by using another thread as a base guide, but have not had too much success with it.

It would be most appreciated, should someone be available to assist me with this problem.
Reply With Quote
  #2 (permalink)  
Old 10-15-11, 03:35
myle myle is offline
(Making Your Life Easy)
 
Join Date: Feb 2004
Location: New Zealand
Posts: 1,143
Why not just remove the .s and make it a number
__________________
hope this help

See clear as mud


StePhan McKillen
the aim is store once, not store multiple times
Remember... Optimize 'til you die!
Progaming environment:
Access based on my own environment: DAO3.6/A97/A2000/A2003
VB based on my own environment: vb6 sp5
ASP based on my own environment: 5.6
VB-NET based on my own environment started 2007
SQL-2005 based on my own environment started 2008
MYLE
Reply With Quote
  #3 (permalink)  
Old 10-17-11, 10:13
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Using that versioning convention, the easiest way would be to write a VBA UDF. So that it considers 3 to be greater than 22, etc, you have to perform string comparisons rather than numeric comparisons. Not sure if you want that for the major part of the version too? If not, change the code below so it casts the strings to longs before comparing them with >.
Code:
Public Function GetLatestVersion(ByVal rngToCheck As Range) As Variant
 
    Const strDELIMITER As String = "."
 
    'version convention:  Major.Minor.Patch   eg  1.3.2
 
    Dim strMaxMajor As String
    Dim strMaxMinor As String
    Dim strMaxPatch As String
    Dim strVersion() As String
 
    Dim rngCell As Range
 
    On Error GoTo ErrorExit
 
    For Each rngCell In rngToCheck.Cells
 
        If Not IsEmpty(rngCell.Value2) Then
 
            strVersion = Split(rngCell.Value2, strDELIMITER)
 
            If strMaxMajor = vbNullString Then
                If IsNumeric(strVersion(0)) Then
                    strMaxMajor = strVersion(0)
                    strMaxMinor = strVersion(1)
                    strMaxPatch = strVersion(2)
                End If
            Else
 
                If strVersion(0) > strMaxMajor Then
 
                        strMaxMajor = strVersion(0)
                        strMaxMinor = strVersion(1)
                        strMaxPatch = strVersion(2)
 
                ElseIf strVersion(0) = strMaxMajor Then
 
                    If strVersion(1) > strMaxMinor Then
 
                        strMaxMajor = strVersion(0)
                        strMaxMinor = strVersion(1)
                        strMaxPatch = strVersion(2)
 
                    ElseIf strVersion(1) = strMaxMinor Then
 
                         If strVersion(2) > strMaxPatch Then
 
                            strMaxMajor = strVersion(0)
                            strMaxMinor = strVersion(1)
                            strMaxPatch = strVersion(2)
 
                        End If
 
                    End If
                Else
 
                End If
            End If
        End If
    Next rngCell
 
    GetLatestVersion = strMaxMajor & strDELIMITER & strMaxMinor & strDELIMITER & strMaxPatch
 
    Exit Function
 
ErrorExit:
    GetLatestVersion = CVErr(xlErrNum)
End Function
Once that's in a standard code module, you can call it from your formulae like this:

=GetLatestVersion(E3:E5)
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA

Last edited by Colin Legg; 10-17-11 at 10:30.
Reply With Quote
Reply

Tags
compare, custom number, excel, high, version number

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On