|
- Dim s&
- Sub Macro1()
- '&为长整型变量简写
- Dim c As Range, arr, i&, x&
- s = s + 1
- If s > 1 Then Exit Sub '限定运行一次代码,避免重复插入行
- arr = Range("g3").CurrentRegion
- For i = 2 To UBound(arr) '循环数组,在b列中从后往前查找
- Set c = Range("b3").CurrentRegion.Find(arr(i, 1), searchdirection:=xlPrevious)
- If Not c Is Nothing Then
- '如果查找到该值,向后插入一行
- x = c.Row + 1
- Range("b" & x).Resize(1, 3).Insert Shift:=xlDown
- Else
- '否则取最后一行+1
- x = Cells(Rows.Count, 2).End(xlUp).Row + 1
- End If
- '赋值
- Cells(x, 2) = arr(i, 1)
- Cells(x, 4) = arr(i, 2)
- Next
- End Sub
复制代码 |
|