當前位置:成語大全網 - 新華字典 - excel中兩列數據轉換成多行多列的宏代碼?

excel中兩列數據轉換成多行多列的宏代碼?

妳的數據在AB列

我在速度方面優化了壹下,試試能否滿足需要

Sub Macro1()

'

' Macro1 Macro

'

'

Dim I As Integer, zROW As Integer, zR2 As Integer

Dim zDATA()

zROW = Range("A1").End(xlDown).Row

ReDim zDATA(zROW, 2)

zDATA = Range("A1:B" & zROW)

zR2 = 0

Application.ScreenUpdating = False

For I = 1 To zROW

If Columns("C:C").Find(What:=zDATA(I, 1)) Is Nothing Then

zR2 = zR2 + 1

Cells(zR2, 3) = zDATA(I, 1)

Cells(zR2, 4) = zDATA(I, 2)

Else

Columns("C:C").Find(What:=zDATA(I, 1)).End(xlToRight).Next = zDATA(I, 2)

End If

Next

Application.ScreenUpdating = True

End Sub