寻找长度为2个字符或1个字符的单元格

时间:2015-12-04 14:01:34

标签: excel-vba vba excel

我正在寻找长度为1或2个字符的单元格。 这是代码:

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

1 个答案:

答案 0 :(得分:2)

您可以使用循环而不是 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