Mac
Mac

Reputation: 327

Looking for Cells with length of 2 characters or 1 character

I'm looking for cells with length of value 1 or 2 characters. This is code:

Set c = .Find(Len(c.Value) = 2 Or 1, LookIn:=xlValues)

Upvotes: 0

Views: 45

Answers (1)

Gary's Student
Gary's Student

Reputation: 96791

You can use a loop rather than FIND():

Sub durale()
   For Each r In ActiveSheet.UsedRange
      If Len(r.Value) = 2 Or Len(r.Value) = 1 Then
         Set c = r
         Exit For
      End If
   Next r

   If c Is Nothing Then
      MsgBox "nothing found"
   Else
      MsgBox "cell " & r.Address(0, 0) & "contains " & r.Value
   End If
End Sub

Upvotes: 2

Related Questions