|
为了测试保留原数据,输出到sheet3(工作表名"sheet2")
- Sub test()
- With Sheet1
- ar = .UsedRange
- r = .Cells(Rows.Count, "A").End(3).Row
- c = .UsedRange.Columns.Count
- ReDim arr(1 To 7, 1 To 1)
- ReDim brr(1 To 7, 1 To 1)
- For i = 2 To r Step 6
- temp = .Range(.Cells(i, "D"), .Cells(i + 5, "D"))
- nn = WorksheetFunction.Small(.Range(.Cells(i, "D"), .Cells(i + 5, "D")), 1)
- For j = 7 To 7 + nn - 1
- For i1 = i To i + 5
- If i1 > r Then Exit For
- If ar(i1, j) <> "" Then
- n = n + 1
- ReDim Preserve arr(1 To 7, 1 To n)
- For j_ = 1 To 6
- arr(j_, n) = ar(i1, j_)
- Next j_
- arr(7, n) = ar(i1, j)
- End If
- Next i1
- Next j
- For i1 = i To i + 5
- If i1 > r Then Exit For
- For j = 7 + nn To c
- If ar(i1, j) <> "" Then
- m = m + 1
- ReDim Preserve brr(1 To 7, 1 To m)
- For j_ = 1 To 6
- brr(j_, m) = ar(i1, j_)
- Next j_
- brr(7, m) = ar(i1, j)
- End If
- Next j
- Next i1
- Next i
- End With
- With Sheet3
- .[a2].Resize(n, 7) = Application.Transpose(arr) '以最小值匹配的数据
- .[a2].Offset(n, 0).Resize(m, 7) = Application.Transpose(brr) '根据匹配数据后未进行匹配的的数据
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|