使用VBA扩展日期范围和关联数据

时间:2016-11-30 09:46:34

标签: excel vba date

我需要处理大量数据才能进行数据分析。 目前,数据位于this form,我的目标是使用VBA生成this

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个。应该适合你的榜样......

Sub Dates()

Dim LastRow As Long
Dim RowIns As Integer

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

For i = 2 To LastRow

Cont:

    If Cells(i, 1).Value = "" Then

        GoTo Cont2

    End If

    RowIns = Cells(i, 4).Value - Cells(i, 3).Value

    If RowIns <= 0 Then

        i = i + 1

        GoTo Cont

    End If

    Rows(i + 1 & ":" & RowIns + i).Insert Shift:=xlDown

    Range("C" & i).Select
    Selection.AutoFill Destination:=Range("C" & i & ":C" & RowIns + i), Type:=xlFillDefault

    Range("A" & i & ":B" & i).Select
    Selection.AutoFill Destination:=Range("A" & i & ":B" & RowIns + i), Type:=xlFillCopy

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

    i = i + RowIns + 1

    GoTo Cont

Next

Cont2:

Columns(4).EntireColumn.Delete

End Sub