0

我需要编写一个简单的宏,如果单元格中的文本不为空,它将在单元格中的文本之前添加一个后缀“'”。IE:

这:
C 列
ASDF
FDSA

法萨达

应改为:
C 列
'ASDF'FDSA

'法萨达

我的代码看起来像这样:(但倒数第二行有一个错误(如果不计算“End Sub”行,则最不重要)

Sub Inserting_apostrophe()
startrow = 1
endrow = 1800

For x = startrow To endrow
    If Cells(x, "C").Value <> "" Then
    Range("C" & x).Value = "'" & "Cells(x, "C").Value" 'This line is unfortunately wrong, could you mend it?

End Sub

提前谢谢大家,
关于阿图尔·鲁特科夫斯基(
Artur Rutkowski )

4

1 回答 1

1

"Cells(x, "C").Value"是问题所在。它不应该用引号引起来。
你也没有完成你的If陈述或For陈述。使用End IfandNext来结束你的If语句并告诉For何时循环。

Sub Inserting_apostrophe()
    Dim startrow as Integer
    Dim endrow as Integer
    Dim x as Integer

    startrow = 1
    endrow = 1800

    For x = startrow To endrow
        If Cells(x, 3).Value <> "" Then
            Range("C" & x).Value = "'" & Cells(x, 3).Value
        End If
    Next
End Sub
于 2013-08-01T13:38:57.517 回答