使用VBA在单元格中添加单引号

Kir*_*ell 5 excel vba excel-vba

我试图通过使用Chr(39)在列中的值上添加单引号,但是我只得到第二个引号。例如,我想要“价值”,但我正在获得价值”

但是,如果我通过使用Chr(34)使用双引号,它将起作用,并且我得到“值”

Sub AddQuote()
Dim myCell As Range
    For Each myCell In Selection
        If myCell.Value <> "" Then
            myCell.Value = Chr(39) & myCell.Value & Chr(39)
        End If
    Next myCell
End Sub
Run Code Online (Sandbox Code Playgroud)

谢谢基兰

why*_*heq 6

只需添加另一个单引号:

Sub AddQuote()
Dim myCell As Range
    For Each myCell In Selection
        If myCell.Value <> "" Then
            myCell.Value = Chr(39) & Chr(39) & myCell.Value & Chr(39)
        End If
    Next myCell
End Sub
Run Code Online (Sandbox Code Playgroud)