用此if语句替换步骤2?

时间:2019-03-06 16:08:06

标签: vba

u / Ahmed AU通过编辑我发布的脚本来帮助我实现这一目标:在Sheet3中获取数据集,每两行插入Step 2,并将其转置到dest单元格中Sheet2。效果很好。

我想做的是用IF语句替换Step 2,该IF语句仅在A列中的员工姓名相同时才将行配对在一起。例如:A2和A3都有雇员1,因此将两行配对并将它们转置到dest范围内。如果A2 <> A3,则分别转置它们。如果值不相等,我将如何编辑此脚本以仅将类似的值转置在一起,然后分别处理它们?我本以为If Data(i,1) <> Last Then语句会起作用,但我不知道将其放置在何处,因此需要取出Step 2一段。

Sub Main()
  Dim wb As Workbook
  Dim Data, Last, Mgr
  Dim Rw As Long, Col As Long
  Dim i As Long, k As Long, j As Long
  Dim Dest As Range, TmpArr As Variant
  Set wb = ThisWorkbook
  Set Dest = wb.Sheets("Sheet2").Range("E1")
  With ThisWorkbook.Sheets("Sheet3")
    Data = .Range("ed2", .Range("A" & Rows.Count).End(xlUp))
  End With

Last = Data(i, 1)

Rw = -1
For i = LBound(Data, 1) To UBound(Data, 1) Step 2
k = 1
If i = UBound(Data) Then k = 0
    For Col = LBound(Data, 2) To UBound(Data, 2)
    Rw = Rw + 1
        For j = 0 To k
        Dest.Offset(Rw, j).Value = Data(i + j, Col)
        Next j
    Next Col
Next i

End Sub

0 个答案:

没有答案