[英]How to Fill cell background color depending a specific value from another sheet cell value in excel?
試一下:
Sub test()
Dim rng1 As Range, rng2 As Range, cell As Range, rngFound As Range
Dim ws1 As Worksheet, ws2 As Worksheet
With ThisWorkbook
Set ws1 = .Worksheets("Sheet1")
Set ws2 = .Worksheets("Sheet2")
End With
With ws1
Set rng1 = .Range("A1:R1")
End With
With ws2
Set rng2 = .Range("A1:E5")
For Each cell In rng2
Set rngFound = rng1.Find(cell.Value, LookIn:=xlValues, Lookat:=xlWhole)
If Not rngFound Is Nothing Then
cell.Interior.ColorIndex = rngFound.Interior.ColorIndex
End If
Next cell
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.