0

I have at least 6 different variables in my codes. 3 of them variants, 3 of them strings. I'd like to count the variants with values and count the strings with values ( like 2 variants, 3 strings ) and check to see if they are equal.

Any ideas?

6
  • 1
    Sample data plus what you already tried would help your question. Commented Jul 20, 2017 at 5:49
  • Variants are dates, simply named as WA1, WA2 and WA3 and strings are texts named as WS_1, WS_2 and WS_3. All of their values comes from other variables or from worksheets with conditions. I didn't tried to count them at first, I just checked them with If condition, but it doesn't work great. So I'm wondering if there is any other way of doing this; 'If WA1 = "" Or WS_1 <> "" And WA1 <> "" And WS_2 <> "" And WA2 <> "" And WS_3 <> "" And WA3 = "" Or WS_1 <> "" And WA1 <> "" And WS_2 <> "" And WA2 = "" And WS_3 = "" Or WS_1 <> "" And WA1 = "" And WS_2 = "" And WS_3 = "" Then' Commented Jul 20, 2017 at 5:52
  • I can't tell what you're doing here. Maybe try explaining in words? You say you want to check if they're equal, but equal to what? Each other? all the same value, or some the same value? Or? Commented Jul 20, 2017 at 6:07
  • There are 3 variants and 3 strings and many loops within the code. At the loops, some times 1 variants and 2 string has a value ( like WA1, WS_1 and WS_2 ) and so on. All I want to do that to check if the count of variants with value is equal to the count of strings with value. Commented Jul 20, 2017 at 6:15
  • I don't want to compare their values, just to check if they have a value other then empty. Commented Jul 20, 2017 at 6:16

2 Answers 2

1

Maybe something like:

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Please, add some explanation of the code. Don't need to be extensive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.