如何创建一个宏来提示当前日期并提前1天更改下一个单元格?我有一个到目前为止的样本。如果我是亲密的,请告诉我。
Sub Change_dates()
Dim dtDate As Date
dtDate = InputBox("Date", , Date)
For Each cell In Intersect(Range("B " & dblRow).Value = dtDate, ActiveSheet.UsedRange)
cell.Offset(0, 1).Select = cell.Offset(0, 1).Select + 1
Next cell
End Sub
答案 0 :(得分:1)
此代码将提示当前日期,写入活动单元格,然后将日期+ 1写入下一列中的单元格。
Sub Change_dates()
Dim dtDate As Date
dtDate = InputBox("Date", , Date)
ActiveCell.Value = dtDate
ActiveCell.Offset(0, 1).Value = dtDate + 1
End Sub
这将从提示中取出日期,将其写入范围中的选定行,然后将日期+ 1放在所选范围右侧的一列中。
Sub Change_dates_range()
Dim dtDate As Date
dtDate = InputBox("Date", , Date)
Set SelRange = Selection
For Each b In SelRange.Rows
b.Value = dtDate
b.Offset(0, 1).Value = dtDate + 1
Next
End Sub
如果您希望范围中的每一行都在前一行的前一天,那么我会在循环结束前将Next语句增加dtDate。
答案 1 :(得分:0)
这应该完全符合您的要求:
Sub Change_dates()
Dim dtDate As Date
Dim rng As Range
Dim FirstRow As Integer
dtDate = InputBox("Date", , Date)
Set rng = ActiveSheet.Columns("B:B").Find(What:=dtDate, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlNext)
FirstRow = rng.Row
Do
rng.Offset(0, 1).Value = rng.Offset(0, 1).Value + 1
Set rng = ActiveSheet.Columns("B:B").FindNext(After:=rng)
Loop Until rng.Row = FirstRow
End Sub