比较2个数字,最多4个小数点

时间:2014-08-07 00:47:03

标签: excel-vba comparison excel-2010 decimal-point vba

我需要比较最多包含4个小数位的软件版本(14.7.3.13)。我有一个静态列表,我正在比较电子表格中的值。如果电子表格中的值> =我的代码中的静态数字,我会突出显示该单元格。 我很难做到这一点。我假设我的问题是数据类型。我已经将我的静态值声明为变体。我可以更改电子表格中的数据类型,但我不知道在电子表格的代码中使用哪些数据类型。

1 个答案:

答案 0 :(得分:0)

您可以在'。'上拆分软件版本吗?字符,然后比较版本的每个“段”?这样的事情:

Dim value1() As String = version1.split(".")
Dim value2() As String = version2.split(".")
Dim greatestVersion As String

greatestVersion = value1 ' Start with greatest version as value1

If version1 = version2 Then ' Check to see if they are both the same
    greatestVersion = "BOTH THE SAME!"
Else If ' If not the same then determine the bigger value
For i=0 To value1.count
    If value2[i] > value1[i] Then
        greatestVersion = version2
    End If
Next




End If