【问题标题】:Vlookup cell background colour from another workbook VBA来自另一个工作簿 VBA 的 Vlookup 单元格背景颜色
【发布时间】:2019-05-07 07:24:33
【问题描述】:

所以我有一个像工作簿一样的甘特图,每个工作人员都有一个唯一的编号(代表一行),然后我想从这一行和一个指定的列中检索单元格颜色,就像普通的 vlookup 一样。见下图。

我希望在对应于日期的单元格中拾取这个绿色,即列和行,即工作编号。

谢谢

【问题讨论】:

  • 您需要使用 VBA 执行此操作 - 公式无法复制颜色。您是否尝试过一些 VBA 来解决这个问题?从您的屏幕截图中并不清楚输入在哪里,或者是什么决定了行上的哪些单元格是彩色的。

标签: excel vba excel-formula colors vlookup


【解决方案1】:

我不确定你在做什么,但反正我有这段代码......

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

示例用法(启用显示公式):

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-01
    • 2021-10-31
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多