標題:
如何從字串中比對後抓出需求的資料
[打印本頁]
作者:
lone_tiger0303
時間:
2012-2-18 22:22
標題:
如何從字串中比對後抓出需求的資料
如何將L欄位字串與工作表"員工名單"比對,
比對到相同的名字抓到AI欄位
問題如附件
作者:
register313
時間:
2012-2-18 23:51
回復
1#
lone_tiger0303
資料量大 執行較週
Sub zz()
Application.ScreenUpdating = False
Dim Rng As Range, Ar
Set Rng = Sheets("DMS").[L2]
Range(Rng, [L65536].End(xlUp)).Offset(0, 23) = ""
Do
If InStr(Rng, ",") Then
Ar = Split(Rng, ",")
For I = 0 To UBound(Ar)
Set X = Sheets("員工名單").UsedRange.Find(Ar(I), , xlValues, xlWhole)
If Not X Is Nothing Then
Rng.Offset(0, 23) = Rng.Offset(0, 23) & X & " "
End If
Next I
Else
Set X = Sheets("員工名單").Cells.Find(Rng, , xlValues, xlWhole)
If Not X Is Nothing Then
Rng.Offset(0, 23) = Rng
End If
End If
Set Rng = Rng.Offset(1)
Loop Until Rng(1) = ""
Application.ScreenUpdating = True
End Sub
複製代碼
[attach]9644[/attach]
作者:
Hsieh
時間:
2012-2-19 00:14
回復
1#
lone_tiger0303
Sub nn()
With Sheets("DMS")
For Each a In .Range("L2", .[L2].End(xlDown))
.Cells(a.Row, "AI") = ""
ar = Split(a, ",")
For Each b In ar
Set c = Sheets("員工名單").Cells.Find(b, lookat:=xlWhole)
If Not c Is Nothing Then .Cells(a.Row, "AI") = IIf(.Cells(a.Row, "AI") = "", c, .Cells(a.Row, "AI") & "," & c)
Next
Next
End With
End Sub
複製代碼
作者:
GBKEE
時間:
2012-2-19 11:13
回復
1#
lone_tiger0303
Option Explicit
Sub Ex()
Dim Ar, xA, xF As Range, xS As Integer
With Sheets("DMS")
Ar = Application.Transpose(.Range("L1", .[L1].End(xlDown)).Value)
Ar = Join(Ar, ",")
Ar = Split(Ar, ",")
With .Range("IR1")
.Resize(UBound(Ar)) = Application.Transpose(Ar)
.Resize(UBound(Ar)).Offset(, 1) = 1
xA = .Resize(UBound(Ar)).Resize(, 2).Address(, , 0)
.Offset(, 2).Consolidate xA, xlSum, 0, 1 '彙算出不重複的名單
Erase Ar
For Each xA In .Offset(, 2).Resize(Rows.Count, 1).SpecialCells(xlCellTypeConstants)
If xA.Row <> 1 And xA <> "" Then
Set xF = Sheets("員工名單").Cells.Find(xA, lookat:=xlWhole)
If Not xF Is Nothing Then
ReDim Preserve Ar(xS)
Ar(xS) = xA
xS = xS + 1
End If
End If
Next
.CurrentRegion = ""
End With
If xS > 0 Then
.Range("AI2:AI" & Rows.Count) = ""
.Range("AI2").Resize(xS).Value = Application.Transpose(Ar)
End If
End With
End Sub
複製代碼
作者:
lone_tiger0303
時間:
2012-2-19 12:21
感謝三位老師的指導~~
另外,GBKEE老師~~我要一對一~~重複的名單不用刪除,且不用往上移
作者:
GBKEE
時間:
2012-2-19 15:44
回復
5#
lone_tiger0303
一對一~~重複的名單不用刪除,且不用往上移
做個範例說明一下
作者:
lone_tiger0303
時間:
2012-2-22 12:27
GBKEE老師~~範例如附件
作者:
GBKEE
時間:
2012-2-22 13:23
回復
7#
lone_tiger0303
Option Explicit
Sub Ex()
Dim Ar(), xR As String, xF As Range, xS As Integer
With Sheets("DMS")
Ar = .Range("L2", .[L2].End(xlDown)).Value
For xS = 1 To UBound(Ar)
xR = Split(Ar(xS, 1), ",")(0)
Set xF = Sheets("員工名單").Cells.Find(xR, lookat:=xlWhole)
If Not xF Is Nothing Then
Ar(xS, 1) = xF
Else
Ar(xS, 1) = ""
End If
Next
.Range("AI2:AI" & Rows.Count) = ""
.[AI2].Resize(UBound(Ar)) = Ar
End With
End Sub
複製代碼
作者:
lone_tiger0303
時間:
2012-2-23 12:26
測試OK~~感謝您的協助
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)