使用VBA将文本添加到Excel中的单元格
我一直在使用SQL和Excel宏,但是我不知道如何向单元格中添加文本.
I've been working with SQL and Excel Macros, but I don't know how to add text to a cell.
我希望将文本"01/01/13 00:00"
添加到单元格A1
.我不能只将其写在单元格中,因为宏会先清除工作表的内容,然后再添加信息.
I wish to add the text "01/01/13 00:00"
to cell A1
. I can't just write it in the cell because the macro clears the contents of the sheet first and adds the information afterwards.
如何在VBA中做到这一点?
How do I do that in VBA?
Range("$A$1").Value = "'01/01/13 00:00"
会做到.
请注意单引号;这将使自动转换为数字类型失败.但是,这正是您真正想要的吗?一种替代方法是将单元格格式化为采用日期时间值.然后从字符串中删除单引号.
Note the single quote; this will defeat automatic conversion to a number type. But is that what you really want? An alternative would be to format the cell to take a date-time value. Then drop the single quote from the string.