Home > other >  Comparing multiple variables to one string (at once)
Comparing multiple variables to one string (at once)

Time:12-29

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

CodePudding user response:

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"
  • Related