下个月打印

时间:2019-05-30 12:28:08

标签: vba excel-vba excel-2010

我希望Excel在行的下一行上打印下个月的日期。 (第三行有一个计数器)

例如:

B28 = 01.07.2019 C24 = 01.06.2019  D16 = 01.02.2019 E19 = 01.07.2019

能请你帮我吗?

以下是屏幕截图:https://ibb.co/d0mW8GB

2 个答案:

答案 0 :(得分:1)

您的问题中有很多遗漏的部分,但是我尝试创建代码来满足您的需求。您可以尝试:

Option Explicit

Sub makro3()

    Dim LastColumn As Long, LastRow As Long, Column As Long, Row As Long, Paid As Long

    'In your quetion there is no starting date so i use the current one

    With ThisWorkbook.Sheets("Sheet1")

        LastColumn = .Cells(3, .Columns.Count).End(xlToLeft).Column

        For Column = 2 To LastColumn

            Paid = .Cells(3, Column).Value

            For Row = 1 To Paid

                LastRow = .Cells(.Rows.Count, Column).End(xlUp).Row

                .Cells(LastRow + 1, Column).Value = DateAdd("m", Row, Date)

            Next Row

        Next Column

    End With

End Sub

结果:

enter image description here

答案 1 :(得分:0)

是的,您是对的。

缺少部分:

  1. “无起始日期”-起始日期是每列中的最后日期。例如,对于B列,它是B27,对于C列,它是C24。
  2. “多少个数据”。当您单击命令按钮时,您应该只获得一个日期。只是下个月的日期。