|
先说说你想实现的,你看看对不对:
1、60列做一组,1-60 一直到 22-81 。81列共分成 22 组。
2、D列输入条件,例如 输入31 。则要按组找出各组中出现次数为31的数,因为单列不重复,所有出现的次数也可以理解为 有31列中含有这个数,就找出来。
3、如果输入多个数字,比如输入 31 18 ,那只要出现31次或者18次,都找出来合并去重作为该组的输出结果。
下面代码结果和你示例结果有差异,你自己找下是你的错还是我的错。
- Sub BBB()
- Dim t
- Dim Arr, Brr(999) As Long, Crr, Drr
- Dim I As Long, J As Long, K As Long, N As Long, Lrow As Long, Lcol As Long, M As Long
- t = Timer
- Arr = Sheets("SHEET1").Range("G1").CurrentRegion '源数据
- Crr = Sheets("SHEET1").Range("D1:D" & Sheets("SHEET1").Range("D" & Rows.Count).End(xlUp).Row) '输入数据
- Lrow = UBound(Arr)
- Lcol = UBound(Arr, 2)
- ReDim Drr(1 To Lrow, 1 To Lcol - 59) '结果数据
- For I = 1 To 60
- For K = 1 To Lrow
- If Len(Arr(K, I)) <> 0 Then
- M = Val(Arr(K, I))
- Brr(M) = Brr(M) + 1
- End If
- Next
- Next
- For J = 0 To 999
- For K = 1 To UBound(Crr)
- If Brr(J) = Crr(K, 1) Then
- N = N + 1
- Drr(N, 1) = Format(J, "000")
- Exit For
- End If
- Next
- Next
- For I = 1 To Lcol - 60
- For K = 1 To Lrow
- If Len(Arr(K, I)) <> 0 Then
- M = Val(Arr(K, I))
- Brr(M) = Brr(M) - 1
- End If
- If Len(Arr(K, I + 60)) <> 0 Then
- M = Val(Arr(K, I + 60))
- Brr(M) = Brr(M) + 1
- End If
- Next
- N = 0
- For J = 0 To 999
- For K = 1 To UBound(Crr)
- If Brr(J) = Crr(K, 1) Then
- N = N + 1
- Drr(N, I + 1) = Format(J, "000")
- Exit For
- End If
- Next
- Next
- Next
- Sheets("SHEET2").Cells.Clear
- Sheets("SHEET2").Range("B1").Resize(Lrow, Lcol - 59).NumberFormatLocal = "@"
- Sheets("SHEET2").Range("B1").Resize(Lrow, Lcol - 59) = Drr
- MsgBox Timer - t
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|