|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
借个楼学习一下数组,哈
Sub test()
arr = Sheets("sheet2").[a11].CurrentRegion
lastr = Sheets("sheet2").Cells(Rows.Count, "a").End(xlUp).Row
brr = Range("z10:z" & lastr)
bz = False
For i = 2 To UBound(arr)
If arr(i, 1) <> "" Then
For j = i + 1 To UBound(arr)
If arr(j, 1) <> "" Then
If arr(i, 12) = arr(j, 12) And arr(i, 16) = arr(j, 16) And arr(i, 18) = arr(j, 18) Then
If brr(i, 1) = "" Then
brr(i, 1) = arr(i, 19)
brr(j, 1) = arr(i, 19) + arr(j, 19)
t = brr(j, 1)
arr(j, 1) = vbNullString
bz = True
Else
brr(j, 1) = t + arr(j, 19)
t = brr(j, 1)
arr(j, 1) = vbNullString
End If
End If
End If
Next
If bz = True Then
bz = False
Else
brr(i, 1) = arr(i, 19)
End If
End If
Next
Sheets("sheet2").[z10].Resize(UBound(brr), 1) = brr
End Sub
|
|