如何复制特定的行并将数据转置到另一个工作表中

时间:2019-09-10 12:59:01

标签: excel vba

我有两个工作表,分别称为“输入”和“ TransformData”。我每天都从部门获得数据,我想自动化其数据转换过程。 “输入”表看起来像这样。

enter image description here

这是输入页。它包含转换数据表所需的所有数据。逻辑是应该分三个阶段进行。 阶段1:加载新数据(可以使用复制粘贴新数据来完成)。 阶段2:删除所有不包含值的行。我已经通过使用以下代码来做到这一点。

   Sub CleanUpData()
    Dim Firstrow As Long
    Dim Lastrow As Long
    Dim Lrow As Long
    Dim CalcMode As Long
    Dim ViewMode As Long
    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    'We use the ActiveSheet but you can replace this with
    'Sheets("MySheet")if you want
    With Sheets("Input Sheet")
        'We select the sheet so we can change the window view
        .Select
        'If you are in Page Break Preview Or Page Layout view go
        'back to normal view, we do this for speed
        ViewMode = ActiveWindow.View
        ActiveWindow.View = xlNormalView
        'Turn off Page Breaks, we do this for speed
        .DisplayPageBreaks = False
        'Set the first and last row to loop through
        Firstrow = .UsedRange.Cells(1).Row
        Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
        'We loop from Lastrow to Firstrow (bottom to top)
        For Lrow = Lastrow To Firstrow Step -1
            'We check the values in the A column in this example
            With .Cells(Lrow, "A")
                If Not IsError(.Value) Then
                    If .Value = "None" Then .EntireRow.Delete
                    'This will delete each row with the Value "ron"
                    'in Column A, case sensitive.
                End If
            End With
        Next Lrow
    End With
    ActiveWindow.View = ViewMode
    With Application
        .ScreenUpdating = True
        .Calculation = CalcMode
    End With
End Sub

这部分工作正常。 现在,我正在过程的-3阶段。此阶段的逻辑是在“卸货端口”列中有三个条目(有时会有三个以上的条目)。该过程应仅从“端口排放”列中复制一个值,并且“容器类型”列中与这些行相对应的所有三个值都将是“日期”列的标题,该列中的所有值都应在相关字段中进行转换与行的引用。输出应该是这样的。

enter image description here

我正在尝试获取上述示例的VBA代码。非常感谢您能提供的任何帮助。在此先感谢社区的所有成员。

0 个答案:

没有答案