有没有办法修改这段代码,使替换的值也突出显示?
最后一行用一个偏移值替换了找到的值(通常只是为了纠正语法),我还尝试让它把单元格背景着色为绿色。
Sub test_Dam()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim f As Range
Dim i As Long, col1 As Long, ini As Long
'set worksheet
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Brands")
Set f = sh1.Cells.Find("Brand", , xlValues, xlPart, , , False)
If Not f Is Nothing Then
col1 = f.Column
ini = f.Row + 2
For i = ini To sh1.Cells(Rows.Count, col1).End(3).Row
Set f = sh2.Cells.Find(sh1.Cells(i, col1).Value, , xlFormulas, xlPart, xlByRows, xlNext, False)
If Not f Is Nothing Then
sh1.Cells(i, col1).Value = f.Offset(0, 0).Value ' trying to add this to highlight
End If
Next
End If
End Sub
1条答案
按热度按时间6bc51xsx1#
下面是如何给一个单元格着色:
HERE IS A DETAIL OF COLOR AND COLORINDEX