简体   繁体   中英

Vlookup cell background colour from another workbook VBA

So I have a Gant chart like workbook that has a unique number for each worker (representing a row) then I want to retrieve the cell color from this row and a specified column, much like a normal vlookup. see image below.

在此处输入图片说明

I want this green to be picked up in the cell corresponding to the day ie the column and the row ie Job no.

Thanks

I'm not sure exactly what you're doing but since i have this code anyway...

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

Example usage (with show formulas enabled):

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM