删除基于第一个字符的单元格内容 - VBA BEGINNER

时间:2017-01-13 17:59:12

标签: vba excel-vba excel

我正在尝试编写代码来清除B列中带引号"作为第一个角色。非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

考虑:

Sub KlearUp()
    Dim rng As Range, r As Range, rKill As Range
    Set rng = Range("B:B").Cells.SpecialCells(xlCellTypeConstants)
    For Each r In rng
        If Left(r.Value, 1) = Chr(34) Then
            If rKill Is Nothing Then
                Set rKill = r
            Else
                Set rKill = Union(r, rKill)
            End If
        End If
    Next r

    If rKill Is Nothing Then
    Else
        rKill.Clear
    End If
End Sub

修改#1:

如果单元格包含公式而不是常量,则替换:

Set rng = Range("B:B").Cells.SpecialCells(xlCellTypeConstants)

使用:

Set rng = Range("B:B").Cells.SpecialCells(xlCellTypeFormulas)