使用VBA将文本添加到Excel中的单元格 [英] Adding text to a cell in Excel using VBA

查看:388
本文介绍了使用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.

这篇关于使用VBA将文本添加到Excel中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆