|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub zhengli()
Dim ar As Variant
Dim br()
With Sheet1
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:g" & r)
ReDim br(1 To UBound(ar) * 10, 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If Trim(ar(i, 5)) <> "" And Trim(ar(i, 7)) <> "" Then
If ar(i, 5) > ar(i, 7) Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
br(n, 5) = br(n, 7)
sl = ar(i, 5) - ar(i, 7)
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
br(n, 5) = sl
br(n, 7) = sl
ElseIf ar(i, 5) < ar(i, 7) Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
br(n, 7) = br(n, 5)
sl = ar(i, 7) - ar(i, 5)
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
br(n, 5) = sl
br(n, 7) = sl
End If
ElseIf Trim(ar(i, 5)) <> "" And Trim(ar(i, 7)) = "" Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
br(n, 7) = br(n, 5)
ElseIf Trim(ar(i, 5)) = "" And Trim(ar(i, 7)) <> "" Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
br(n, 5) = br(n, 7)
End If
Next i
rs = .Cells(Rows.Count, 9).End(xlUp).Row + 1
.Range("i2:o" & rs) = Empty
.[i2].Resize(n, UBound(br, 2)) = br
End With
MsgBox "ok!"
End Sub
|
|