返回列表 上一主題 發帖

[字典物件]單一欄位的值與多個陣列比對後並分類至不同欄位

回復 3# greetingsfromtw
不用字典物件也可以試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Rng As Range, R As Range, E As Range, i(1 To 2) As Integer
  4.     With Range("J1").CurrentRegion
  5.         i(1) = .Columns.Count + 1
  6.         Set Rng = .Rows("2:" & .Rows.Count).SpecialCells(xlCellTypeConstants)  '比對字串
  7.     End With
  8.     Range([A2], [A2].End(xlDown)).Offset(, 1).Resize(, i(1)) = ""
  9.     For Each R In Range([A2], [A2].End(xlDown)) '原始資料迴圈
  10.             i(2) = i(1)
  11.             For Each E In Rng
  12.                 If InStr(UCase(R), UCase(E)) Then
  13.                     i(2) = E.Column - Range("J1").Column + 1
  14.                     Exit For
  15.                 End If
  16.             Next
  17.           With Cells(65536, 1 + i(2))
  18.             If .EntireColumn.Find(R, Lookat:=xlPart) Is Nothing Then .End(xlUp).Offset(1) = R
  19.             '資料不重複
  20.           End With
  21.     Next
  22. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 稻穗結得越飽滿,越會往下垂,一個人越有成就,就要越有謙沖的胸襟。
返回列表 上一主題