VBA如何用值对variables进行计数

我的代码中至less有6个不同的variables。 其中3个变体,其中3个是string。 我想用variables计数值,并用值(如2个variables,3个string)计数string,并检查它们是否相等。

有任何想法吗?

也许是这样的:

Sub Tester() Dim WA1, WA2, WA3 Dim WS1 As String, WS2 As String, WS3 As String WA2 = Now WS3 = "then" If CountValues(WA1, WA2, WA3) = CountValues(WS1, WS2, WS3) Then Debug.Print "same!" End If End Sub 'of the arguments passed, count how many have a value Function CountValues(ParamArray vals()) Dim i As Long, v For Each v In vals If Len(v) > 0 Then i = i + 1 Next v CountValues = i End Function