Private Sub CommandButton1_Click()
Dim i%, c As Range
Do
i = i + 1
sr = Sheet2.Cells(i, 1).Value
If sr = "" Then Exit Do
Set c = Sheet1.[A:A].Find(sr, lookat:=xlWhole)
If Not c Is Nothing Then
Sheet2.Cells(i, 2) = c.Offset(0, 1).Value
Sheet2.Cells(i, 2).Interior.ColorIndex = 3
End If
Loop
End Sub
替换的标记成了红色, 已测试通过
Sub 替换()
For i = 1 To 100
With Sheet1
If Application.CountIf(Sheet2.Range("a:a"), .Cells(i, 1)) > 0 Then
.Cells(i, 2) = Application.VLookup(.Cells(i, 1), Sheet2.Range("a:b"), 2, 0)
End If
End With
Next
End Sub
这其实公式就能办到 百度vlookup
如果非得用vba 我可以提供代码