本帖最后由 excelvlookup 于 2018-10-1 17:02 编辑
Sub aa()
rw = Sheet1.Cells(Rows.Count, 3).End(3).Row
ar = Sheet1.Range("c4:e" & rw)
ReDim br(1 To 3, 9, 1 To UBound(ar))
ReDim cr(1 To 3, 9, 1 To UBound(ar))
For i = 1 To UBound(ar)
For j = 1 To 3
cr(j, ar(i, j), i) = ar(i, j)
For k = 0 To 9
If cr(j, k, i) = "" Then
If i = 1 Then
br(j, k, i) = 1
Else
br(j, k, i) = br(j, k, i - 1) + 1
br(j, k, i - 1) = ""
End If
Else
br(j, k, i) = 0
End If
Next
Next
Next
For i = 1 To 3
ReDim rr(1 To UBound(ar), 9)
For j = 0 To 9
For k = 1 To UBound(ar)
If cr(i, j, k) <> "" Then
rr(k, j) = cr(i, j, k)
Else
rr(k, j) = br(i, j, k)
End If
Next
Next
Sheet1.Cells(4, (i - 1) * 10 + 6).Resize(UBound(ar), 10) = rr
Next
End Sub
Sub bb()
rw = Sheet1.Cells(Rows.Count, 3).End(3).Row
ar = Sheet1.Cells(rw - 1, 6).Resize(2, 30)
br = Sheet1.Cells(rw - 1, 3).Resize(2, 3)
If Application.Sum(Range("f" & rw & ":ai" & rw)) = 0 Then
For i = 1 To 3
For j = 1 To 10
If j - 1 = br(1, i) Then
ar(2, (i - 1) * 10 + j) = 1
Else
ar(2, (i - 1) * 10 + j) = ar(1, (i - 1) * 10 + j) + 1
If j - 1 <> br(2, i) Then
ar(1, (i - 1) * 10 + j) = ""
End If
End If
Next
ar(2, (i - 1) * 10 + br(2, i) + 1) = br(2, i)
Next
Sheet1.Cells(rw - 1, 6).Resize(2, 30) = ar
End If
End Sub
全表重写用aa(),不重写用bb(),bb()必须最少有两期号码,且如果前期计算错误会一直错下去。
即使有aa()重写全表,计算一万个号码也不超过1秒。VBA没有你18楼所说的局限性。
|