推进一系列细胞1个月

时间:2015-01-19 21:46:41

标签: excel vba excel-vba

我有一些表,其中列是日期,我有一个按钮可以将所有这些日期提前1个月。该按钮与以下代码绑定,但它不起作用,而是向我发出一条提示400的警报。任何帮助表示赞赏

Sub advanceDatebyOneMonth()

   Dim DateCell As Range
   Dim DateRange As Range

   Set DateRange = Range("C11:C26,C32:C40,C46:C54")

   For Each DateCell In DateRange.Cells

      Dim firstDate As Date, secondDate As Date
      firstDate = DateValue(DateCell.Value)
      secondDate = DateAdd("m", 1, firstDate)
      Range(DateCell).Value = secondDate

   Next DateCell

End Sub

1 个答案:

答案 0 :(得分:3)

这一行:

Range(DateCell).Value = secondDate  

应该是:

DateCell.Value = secondDate  

由于DateCell已经是一个范围