Dominik Dusza
Dominik Dusza

Reputation: 3

Comparing multiple variables to one string (at once)

Is there any neater way (than presented below) to encode multiple AND comparison?

If a = "Not identified" And _
     b = "Not identified" And _
     c = "Not identified" And _
     c = "Not identified" And _
     d = "Not identified" And _
     e = "Not identified" And _
     f = "Not identified" And _
     g = "Not identified" Then

I have tried to google this for 20 minutes and found nothing. I expect a logical comparison encoded in one - two lines of code. Something like:

If WorksheetFunction.TextJoin("", True, a, b, c, d, e) = WorksheetFunction.Rept("Not identified", 5) Then

Upvotes: 0

Views: 47

Answers (1)

FaneDuru
FaneDuru

Reputation: 42236

Please, try the next way:

Dim rng As Range, strText As String
   
   strText = "Not identified"
   Set rng = Range("C80:C87")
   If rng.cells.count = _
       WorksheetFunction.CountIf(rng, strText) Then Debug.Print "OK"

Upvotes: 2

Related Questions