简体   繁体   English

Excel宏,通过下一行中的按钮添加日期

[英]Excel macro, add date by button in next row

I got problem with adding date button in excel document. 我在Excel文档中添加日期按钮时遇到问题。 I wanted to speed up adding date in document just by clicking the button attached to first row. 我想通过单击第一行所附的按钮来加快在文档中添加日期的速度。 It works almost fine, adding extra cell with date in next row. 它几乎可以正常工作,在下一行添加带有日期的额外单元格。 But when the hour change, all earlier entries change as well. 但是,当小时更改时,所有较早的条目也会更改。 How should I modify it? 我应该如何修改?

    Sub Makro1()
'
' Makro1 Makro
'

'
    Cells(Rows.Count, "B").End(xlUp).Offset(1).Select
    ActiveCell.Formula = "=NOW()"


End Sub

If you want every dates not to change (you just want to keep the NOW() value of when you have called the macro), you could just set the value of the current date to the cell value: 如果您希望每个日期都不变(您只想保留调用宏时的NOW()值),则可以将当前日期的值设置为单元格值:

Sub Makro1()

    Cells(Rows.Count, "B").End(xlUp).Offset(1).Value = NOW()

End Sub

And no need for Select , you can access the value directly. 无需Select ,您可以直接访问该值。 Actually, if you set Now() as a cell formula, the value is supposed to change when a macro (containing the function) worksheet is called or the sheet is recalculated: 实际上,如果将Now()设置为单元格公式,则当调用宏(包含函数)工作表或重新计算工作表时,该值应该会更改:

http://office.microsoft.com/en-au/excel-help/now-function-HP010062293.aspx http://office.microsoft.com/zh-cn/excel-help/now-function-HP010062293.aspx

Hoping that's what you want 希望那是你想要的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM