在excel中修改单元格的button

我需要在Excel工作表中放置一个button来更改单元格内容。

例如,我想填写单元格A2的date结构为dd / mm / yyyy,一旦我select单元格并按下button,单元格内容(date)将向前移动1天。

“2013年1月1日

点击

2013" 年2月1日

这样的事情有可能被执行吗? 你能帮我吗 ?

提前感谢

你需要使用DateAdd() 。 把这个代码放在button点击事件中。 另外将Sheet1更改为相关的图纸名称。

 With ThisWorkbook.Sheets("Sheet1") .Range("A2").Value = DateAdd("d", 1, .Range("A2").Value) End With 

句法

 DateAdd(interval, number, date) 

interval参数具有以下设置:

 yyyy : Year q : Quarter m : Month y : Day of year d : Day w : Weekday ww : Week h : Hour n : Minute s : Second 

跟随评论

我想保持选定的单元格dynamic,换句话说,我不想被限制在单元格A2我需要select任何单元格或一个完整的行或列,并对其应用行动。

尝试这个

 Dim aCell As Range If TypeName(Selection) = "Range" Then For Each aCell In Selection With ThisWorkbook.Sheets("Sheet1") aCell.Value = DateAdd("d", 1, aCell.Value) End With Next End If 

你可以尝试这样的事情

 sub myClick() Selection.Value = Selection.value + 1 end sub