ak47ok 发表于 2014-9-15 16:18
惭愧、在实际应用中有一种情况,自己半天还是没有解决,只好硬着头皮来劳烦老师,增加了返回一列数据的 ... - Sub test()
- '本代码以第一行左右两部份编码定位,要求:
- '左边开始A1;以最后一个编码结束,最后一个编码紧接着的单元格保持为空;
- '右边开始AJ1;以"另一值"单元格"结束,"另一值"与编码之间不留空格."另一值"的名称随意.
- Dim arr, d, i%, j%, brr, aCol%, bCol%, k$, c As Range, c1 As Range
- Sheets("sheet1").Activate
- Set d = CreateObject("scripting.dictionary")
- Set c = Columns("aj").Find(Range("a2"), SearchDirection:=1)
- Set c1 = Columns("aj").Find(Range("a2"), SearchDirection:=2)
- arr = Range(Range("b1").End(xlToRight).Offset(, 1), Range("a65536").End(xlUp))
- brr = Range(c, Cells(c1.Row, Range("ak1").End(xlToRight).Column))
- k = Range("ak1").End(xlToRight): arr(1, UBound(arr, 2)) = k
- For i = 1 To UBound(brr)
- For j = 3 To UBound(brr, 2)
- d(brr(i, 2) & arr(1, j - 1)) = brr(i, j)
- Next
- Next
- For i = 10 To UBound(arr)
- For j = 2 To UBound(arr, 2) - 1
- If InStr(arr(1, j), "反") = 0 Then
- arr(i, j) = IIf(d(arr(i, 1) & arr(1, j)) > arr(2, j), 1, 0)
- Else
- arr(i, j) = IIf(d(arr(i, 1) & arr(1, j)) < arr(2, j), 1, 0)
- End If
- Next
- arr(i, j) = d(arr(i, 1) & k)
- Next
- arr(1, UBound(arr, 2)) = ""
- Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- End Sub
复制代码 |