簡體   English   中英

如何根據excel中另一個工作表單元格值的特定值填充單元格背景顏色?

[英]How to Fill cell background color depending a specific value from another sheet cell value in excel?

如何根據excel中另一個工作表單元格值的特定值填充單元格背景顏色?

我想根據 Sheet1 單元格值填充 sheet2 單元格。

第 1 頁

在此處輸入圖片說明

第 2 頁

在此處輸入圖片說明

例如,在 sheet1 值 4 中缺少這樣,不需要像那樣填充包含值 04 的 sheet2 單元格。

請幫我。

試一下:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM