Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding text to a cell in Excel using VBA

Tags:

excel

vba

I've been working with SQL and Excel Macros, but I don't know how to add text to a cell.

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.

How do I do that in VBA?

like image 832
Phil Avatar asked Dec 16 '13 13:12

Phil


1 Answers

Range("$A$1").Value = "'01/01/13 00:00" will do it.

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.

like image 94
Bathsheba Avatar answered Oct 15 '22 00:10

Bathsheba