簡體   English   中英

從另一個工作簿 VBA Vlookup 單元格背景顏色

[英]Vlookup cell background colour from another workbook VBA

所以我有一個像工作簿這樣的甘特圖,每個工人都有一個唯一的編號(代表一行),然后我想從這一行和指定的列中檢索單元格顏色,就像普通的 vlookup 一樣。 見下圖。

在此處輸入圖片說明

我希望在對應於日期的單元格中選擇這個綠色,即列和行,即工作號。

謝謝

我不確定你在做什么,但因為我有這個代碼......

Function Tester(rngLookup As Range, v)
    Dim c As Range, f As Range, clr As Long

    Set c = Application.ThisCell '<< the cell with the formula
    Set f = rngLookup.Find(v, lookat:=xlWhole)
    If Not f Is Nothing Then
        clr = f.Interior.Color
    Else
        clr = vbWhite
    End If
    'change the background for the cell with the formula
    Application.Evaluate "ChangeColor(""" & c.Parent.Name & """,""" & c.Address() & """," & clr & ")"
    Tester = v 'or whatever is appropriate...
End Function

Sub ChangeColor(sht As String, addr As String, clr As Long)
    ThisWorkbook.Sheets(sht).Range(addr).Interior.Color = clr
End Sub

示例用法(啟用顯示公式):

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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