|
Sub 调整()
Application.ScreenUpdating = False
Dim ar As Variant, cr As Variant
Dim i As Long, r As Long, rs As Long
Dim br()
With Sheets("sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
ar = .Range(.Cells(1, 1), .Cells(r, y))
End With
ReDim br(1 To 50000, 1 To 2)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) = "" Then ar(i, 1) = ar(i - 1, 1)
For j = 2 To UBound(ar, 2)
If Trim(ar(i, j)) <> "" Then
If ar(i, j) <> 0 Then
n = n + 1
br(n, 1) = ar(i, 1)
br(n, 2) = ar(1, j)
End If
End If
Next j
Next i
If n = "" Then MsgBox "没有需要调整的数据!": End
With Sheet2
.Range("a1:b" & .Cells(Rows.Count, 1).End(xlUp).Row) = Empty
.[a1].Resize(n, 2) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|