Вопрос

I'm creating a VBA macro in which I select all empty cells. It works, but even though some cells are empty, Excel doesn't get they're empty until I double-click in them.

Does anybody know why this is?

Это было полезно?

Решение

those cells are cells with zero-length strings.
To be able to evaluate them try using Len function.

Example:

Sub test()

Dim cel, rng As Range, NoVal As Boolean, rngselection As String, i As Long

Set rng = ThisWorkbook.Sheets(1).Range("A1:A5")

rngselection = ""
i = 1
For Each cel In rng
    NoVal = IIf(Len(cel.Value) = 0, True, False)
    If NoVal Then
        If i > 1 Then
            rngselection = rngselection & "," & cel.Address
        Else
            rngselection = cel.Address
        End If
        i = i + 1
    End If
Next cel
Range(rngselection).Select

End Sub

this selects all empty cells in Range("A1:A5").
Code above is tested and for demonstration purpose only.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top