|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码如下,,,
Sub test()
Dim wb As Workbook, sht As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("sheet1")
r = sht.Cells(Rows.Count, 1).End(3).Row
arr = sht.[a1].Resize(r, 8)
s = sht.[n1]
s1 = --Left(s, 1): s2 = --Right(s, 1)
ReDim brr(1 To UBound(arr), 1)
brr(1, 0) = 1
n = 1
For i = 2 To UBound(arr) - 1
If arr(i, 3 + s1) <> Empty And arr(i + 1, 3 + s2) <> Empty Then
n = n + 1
brr(n, 0) = arr(i, 1)
brr(n, 1) = brr(n, 0) - brr(n - 1, 0) - 1
End If
Next
sht.[k1].CurrentRegion.Offset(1).ClearContents
sht.[k2].Resize(n, 2) = brr
Beep
End Sub
|
|