Adding text to a cell in Excel using VBA

前端 未结 4 650
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-11 11:31

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

4条回答
  •  一生所求
    2021-01-11 12:18

    You could do

    [A1].Value = "'O1/01/13 00:00"
    

    if you really mean to add it as text (note the apostrophe as the first character).

    The [A1].Value is VBA shorthand for Range("A1").Value.

    If you want to enter a date, you could instead do (edited order with thanks to @SiddharthRout):

    [A1].NumberFormat = "mm/dd/yyyy hh:mm;@"
    [A1].Value = DateValue("01/01/2013 00:00")
    

提交回复
热议问题