跨工作簿的条件格式问题

时间:2014-06-25 14:00:51

标签: excel

我有一个非常简单的表,我应用了条件格式规则。该规则规定突出显示小于特定量的特定颜色的值。但是,我发现当我将工作表复制到另一个工作簿时,突出显示的单元格的颜色会发生显着变化。在这种情况下,它从绿色阴影变为橙色阴影。这是个常见的问题吗?有没有人碰巧知道如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我无法复制此问题。

请将以下代码添加到问题工作簿中。

将光标放在源工作簿中显示为绿色阴影的单元格上,然后运行宏 TestCF()。然后将光标放在目标工作簿中的同一单元格上,再次运行宏 TestCF()

宏显示条件格式设置的字体颜色。我得到两个工作簿的相同输出。也许你会得到不同的输出。

Option Explicit
Sub TestCF()

  Dim InxCF As Long

  With ActiveCell
    Debug.Print "Workbook " & ActiveWorkbook.Name & "  Worksheet " & _
                ActiveSheet.Name & "  Cell " & ColNumToCode(ActiveCell.Column) & ActiveCell.Row
    For InxCF = 1 To .FormatConditions.Count
      Debug.Print "  Format " & InxCF
      With .FormatConditions(InxCF)
        Debug.Print "    Font colour: " & ColourToRGB(.Font.Color)
      End With
    Next
  End With

End Sub
Function ColourToRGB(ByVal Colour As Long) As String

  Dim Red As Long
  Dim Blue As Long
  Dim Green As Long
  Dim BlueGreen As Long

  Red = Colour Mod 256
  BlueGreen = Colour \ 256
  Green = BlueGreen Mod 256
  Blue = BlueGreen \ 256

  ColourToRGB = "RGB(" & Red & ", " & Green & ", " & Blue & ")"

End Function
Function ColNumToCode(ByVal ColNum As Long) As String

  Dim Code As String
  Dim PartNum As Long

  ' Last updated 3 Feb 12.  Adapted to handle three character codes.
  If ColNum = 0 Then
    ColNumToCode = "0"
  Else
    Code = ""
    Do While ColNum > 0
      PartNum = (ColNum - 1) Mod 26
      Code = Chr(65 + PartNum) & Code
      ColNum = (ColNum - PartNum - 1) \ 26
    Loop
  End If

  ColNumToCode = Code

End Function
相关问题