在特定数字前加撇号

时间:2019-06-04 00:43:41

标签: excel vba

仅当列中的数字以“ 0”开头时,我才尝试在该列的数字前添加撇号。列中混合了许多不同的数字,但是对于并非以零开头的数字,我不希望添加撇号。

Sub RANGE
    For Each Cell in Range ("E:E")

    If cell.value= starts with a 0 then Cell.value = " ' "

Sub Addapostrophe()
    For Each cell In Selection
        cell.Value = "'" & cell.Value
    Next cell
End Sub

1 个答案:

答案 0 :(得分:0)

这将起作用...

Sub Addapostrophe()

    Dim rng As Range
    Set rng = Range("E:E")

    For Each cell In rng
        If Left(cell.Value, 1) = 0 Then
            cell.Value = "'" & cell.Value
        End If
    Next

End Sub