VBA多个值查找和替换,但也突出显示替换的单元格

时间:2018-10-17 14:10:34

标签: excel vba

我有一个代码,可以从另一张纸的列表中查找并替换一张纸中的值。但是,我需要此代码还突出显示该单元格,或以某种方式对其进行标记,以便以后可以手动对其进行检查。有什么建议么?

代码如下:

Sub ReplaceValues()
Dim FandR As Worksheet
Dim PDH As Worksheet
Dim rng As Range, rngR As Range
Dim i As Long
Dim rngReplacement
Dim c As Range
Dim curVal As String

Set FandR = Sheets("Find and Replace")
Set PDH = ThisWorkbook.Sheets("Paste Data here")
i = PDH.Rows.Count
With PDH
Set rng = .Range("E1", .Range("E" & i).End(xlUp))
End With

With FandR
    Set rngR = FandR.Range("H")

End With


For Each c In rngR
    curVal = c.Value
    c.Interior.Color = vbYellow

    With rng
        .Replace curVal, c.Offset(0, 1).Value, xlWhole, , True

    End With
Next
End Sub

0 个答案:

没有答案