以下代码的意思是,Sheet1表中的描述与是否包括Sheet2表中的描述,如果Sheet2表中的描述属于Sheet1表中描述的子集,那么将Sheet1表中有关的物料编码提取出来放在Sheet1表中的其他单元格中。
Sub a()
Dim l_lastRows1 As Integer
Dim l_lastRows2 As Integer
Dim isValue1 As String
Dim isValue2 As String
Dim isValueOk As String
Dim i, j As Integer
On Error Resume Next
Application.ScreenUpdating = False
Sheets("Sheet2").Activate
l_lastRows2 = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.count
Sheets("Sheet1").Activate
l_lastRows1 = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.count
For i = 2 To l_lastRows1 Step 1
isValue1 = Range("B" & i).Value
For j = 2 To l_lastRows2 Step 1
isValue2 = Sheets("Sheet2").Range("A" & j).Value
isValue2 = "*" & isValue2 & "*"
If isValue1 Like isValue2 Then
'isValueOk = isValueOk & "/" & Range("A" & j).Value
isValueOk = Range("A" & i).Value
Exit For
End If
Next j
If isValueOk <> "" Then
Range("D" & i).Value = isValueOk
End If
isValueOk = ""
Next i
Application.ScreenUpdating = True
End Sub
阅读(2603) | 评论(0) | 转发(0) |