VBA 在第二个sheet中查找第一个sheet中不存在的值
Sub Macro2()
'
' Macro2 Macro
' 宏由 Lizm 录制,时间: 2019/04/10
'
'
Dim colSvcId As Integer
Dim i As Integer
Dim j As Integer
j = 47
Dim valS As String
Dim findRes As Boolean
'查找service_id
For rowSvcId = 2 To 43
valS = Range("C" & rowSvcId).Text
If Len(valS) > 0 Then
findRes = False
' 在sheet4中查找
For i = 5 To 78
If InStr(1, Sheets("Sheet4").Cells(i, 3).Text, valS, 1) > 0 Then
findRes = True
Exit For
End If
Next
'在sheet5中查找
For i = 4 To 22
If InStr(1, Sheets("Sheet5").Cells(i, 3).Text, valS, 1) > 0 Then
findRes = True
Exit For
End If
Next
If (findRes = False) Then
Sheets("Sheet3").Range("C" & j).Value = valS
j = j + 1
End If
End If
Next
'查找packageName(HU)
j = 47
For rowPkgNm = 2 To 43
valS = Range("D" & rowPkgNm).Text
If Len(valS) > 0 Then
findRes = False
' 在sheet4中查找
For i = 5 To 78
If InStr(1, Sheets("Sheet4").Cells(i, 4).Text, valS, 1) > 0 Then
findRes = True
Exit For
End If
Next
'在sheet5中查找
For i = 4 To 22
If InStr(1, Sheets("Sheet5").Cells(i, 4).Text, valS, 1) > 0 Then
findRes = True
Exit For
End If
Next
If (findRes = False) Then
Sheets("Sheet3").Range("D" & j).Value = valS
j = j + 1
End If
End If
Next
'查找base_url
j = 47
For rowBaseUrl = 2 To 43
valS = Range("F" & rowBaseUrl).Text
If Len(valS) > 0 Then
findRes = False
' 在sheet4中查找
For i = 5 To 78
If InStr(1, Sheets("Sheet4").Cells(i, 6).Text, valS, 1) > 0 Then
findRes = True
Exit For
End If
Next
'在sheet5中查找
For i = 4 To 22
If InStr(1, Sheets("Sheet5").Cells(i, 6).Text, valS, 1) > 0 Then
findRes = True
Exit For
End If
Next
If (findRes = False) Then
Sheets("Sheet3").Range("F" & j).Value = valS
j = j + 1
End If
End If
Next
'查找client
j = 47
For rowClient = 2 To 43
valS = Range("G" & rowClient).Text
If Len(valS) > 0 Then
findRes = False
' 在sheet4中查找
For i = 5 To 78
If InStr(1, Sheets("Sheet4").Cells(i, 7).Text, valS, 1) > 0 Then
findRes = True
Exit For
End If
Next
'在sheet5中查找
For i = 4 To 22
If InStr(1, Sheets("Sheet5").Cells(i, 7).Text, valS, 1) > 0 Then
findRes = True
Exit For
End If
Next
If (findRes = False) Then
Sheets("Sheet3").Range("G" & j).Value = rowClient
j = j + 1
End If
End If
Next
End Sub