程式碼如下:
Option Explicit
Sub YgB()
Dim arr, i, i2, j, k, m, n, c As Range
arr = Selection
i = Selection.Cells(1, 1).Row
j = Selection.Cells(1, 1).Column
n = 0
For k = 1 To UBound(arr)
If n 0 Then
If arr(k, 1) > n + 1 Then
Cells(i2, 1).Resize(arr(k, 1) - n - 1, 1).EntireRow.Insert
For Each c In Cells(i2, 1).Resize(arr(k, 1) - n - 1, 1).Cells
n = n + 1
c.Value = n
i2 = i2 + 1
Next c
End If
Else
i2 = i + k
n = arr(k, 1)
Next k
End Sub
執行的拷屏如下:
程式碼如下:
Option Explicit
Sub YgB()
Dim arr, i, i2, j, k, m, n, c As Range
arr = Selection
i = Selection.Cells(1, 1).Row
j = Selection.Cells(1, 1).Column
n = 0
For k = 1 To UBound(arr)
If n 0 Then
If arr(k, 1) > n + 1 Then
Cells(i2, 1).Resize(arr(k, 1) - n - 1, 1).EntireRow.Insert
For Each c In Cells(i2, 1).Resize(arr(k, 1) - n - 1, 1).Cells
n = n + 1
c.Value = n
i2 = i2 + 1
Next c
End If
i2 = i2 + 1
Else
i2 = i + k
End If
n = arr(k, 1)
Next k
End Sub
執行的拷屏如下: