我正在编写一个脚本,将各种类型的数据插入到工作表(ws)中。
当我尝试将字符串
Dim ws as Worksheet
Dim Index_Array(0 to 5) As Variant
Dim i as Integer
Set ws = ActiveSheet
Index_Array(0) = "This is some text."
Index_Array(1) = "This is also some text."
Index_Array(2) = "22004"
Index_Array(3) = 42
Index_Array(4) = 2.34657
Index_Array(5) = "=55" 'Yes, this should in fact be a string, not a formula or a number
For i = LBound(Index_Array) To UBound(Index_Array)
ws.Cells(1, i + 1).Value = Index_Array(i)
Next i
当我尝试将字符串
=55
插入单元格A5时,出现以下错误:除了这种情况外,脚本完全正常,我认为这是因为它试图将其变成公式。我不想强制每个字符串都以Run-time Error 1004: Application-defined or object-defined error。
'
字符开头,因为并非所有内容都是字符串。有没有一种简单的方法可以使Excel接受以等号开头的字符串作为单元格值?
=
,则需要添加撇号,或者将单元格格式设置为文本
。 - JohnyL