我知道如何为顺序缺失值插入行,但是如何为存储在范围内的唯一值执行此操作?例如:
Range of all needed values New list with missing values
2 2
3 5
5 7
6 15
7
10
15
下面的代码在序列中添加行(即如果列表是2 3 5,它会增加4)所以它不是我需要的但我不知道如何使它循环遍历范围并仅从中获取值
Sub RowsInSequence()
Dim i As Long, j As Long
i = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For j = i To 1 Step -1
If Cells(j + 1, 1) <> "" Then
If Cells(j + 1, 1).Value - Cells(j, 1).Value > 1 Then
x = Cells(j + 1, 1).Value - Cells(j, 1).Value
Rows(j + 1 & ":" & x + j - 1).Insert
End If
End If
Next j
With Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
.Formula = "=Row()"
.Value = .Value
End With
Application.ScreenUpdating = True
End Sub