Ir ao conteúdo
  • Cadastre-se

Cor RGB de células no excel


Posts recomendados

Olá, bom dia

 

Depois muita pesquisa e tempo demandado cheguei a um código que permite mostrar as cores das células que realmente elas aparecem. Por exemplo quando pintamos uma célula e colocamos na mesma uma formatação condicional a cor mostrada nas VBAs ou na função CÉL do excel nunca é a da formatação condicional.

Porém este código permite retornar a cor sempre que aparece na tela.

Abaixo está o código:

' Arguments
' ----------------
' Cell - Required Range, not a String value, for a **single** cell
'
' CellInterior - Optional Boolean (Default = True)
'                True makes function return cell's Interior Color or ColorIndex based on
'                the ReturnColorIndex argument False makes function return Font's Color or
'                ColorIndex based on the ReturnColorIndex argument
'
' ReturnColorIndex - Optional Boolean (Default = True)
'                    True makes function return the ColorIndex for the cell property determined
'                    by the CellInterior argument False make function return the Color for the
'                    cell property determined by the CellInterior argument
'
Function DisplayedColor(Cell As Range, Optional CellInterior As Boolean = True, _
                        Optional ReturnColorIndex As Long = True) As Long
  Dim X As Long, Test As Boolean, CurrentCell As String
  If Cell.Count > 1 Then Err.Raise vbObjectError - 999, , "Only single cell references allowed for 1st argument."
  CurrentCell = ActiveCell.Address
  For X = 1 To Cell.FormatConditions.Count
    With Cell.FormatConditions(X)
      If .Type = xlCellValue Then
        Select Case .Operator
          Case xlBetween:      Test = Cell.Value >= Evaluate(.Formula1) And Cell.Value <= Evaluate(.Formula2)
          Case xlNotBetween:   Test = Cell.Value <= Evaluate(.Formula1) Or Cell.Value >= Evaluate(.Formula2)
          Case xlEqual:        Test = Evaluate(.Formula1) = Cell.Value
          Case xlNotEqual:     Test = Evaluate(.Formula1) <> Cell.Value
          Case xlGreater:      Test = Cell.Value > Evaluate(.Formula1)
          Case xlLess:         Test = Cell.Value < Evaluate(.Formula1)
          Case xlGreaterEqual: Test = Cell.Value >= Evaluate(.Formula1)
          Case xlLessEqual:    Test = Cell.Value <= Evaluate(.Formula1)
        End Select
      ElseIf .Type = xlExpression Then
        Application.ScreenUpdating = False
        Cell.Select
        Test = Evaluate(.Formula1)
        Range(CurrentCell).Select
        Application.ScreenUpdating = True
      End If
      If Test Then
        If CellInterior Then
          DisplayedColor = IIf(ReturnColorIndex, .Interior.ColorIndex, .Interior.Color)
        Else
          DisplayedColor = IIf(ReturnColorIndex, .Font.ColorIndex, .Font.Color)
        End If
        Exit Function
      End If
    End With
  Next
  If CellInterior Then
    DisplayedColor = IIf(ReturnColorIndex, Cell.Interior.ColorIndex, Cell.Interior.Color)
  Else
    DisplayedColor = IIf(ReturnColorIndex, Cell.Font.ColorIndex, Cell.Font.Color)
  End If
End Function

 

Porém gostaria de uma ajuda para que o valor que esta função retorne seja em RGB, como por exemplo "Red - 255, Green - 255, Blue - 255";

 

Att.

 

RGB-FormatCond R0-v4.rar

Link para o comentário
Compartilhar em outros sites

Basole muito obrigado pela ajuda.

 

Mas há como fazer com que o valor 1(cor preta das células B6~B11) apareça como RGB(0,0,0) ou seja o correspondente a cor usada na formatação condicional, mesmo quando a formatação estiver ativa(valor 1 na célula B5) ou inativa (célula B5 vazia)?

se for possível ficaria perfeito.

 

Att.

 

RGB-FormatCond R0-v5.rar

Link para o comentário
Compartilhar em outros sites

@Basole EXCELENTE!!!!!

 

Testei bastante e está funcionando perfeitamente.

 

Muito obrigado pela força.

adicionado 0 minutos depois
51 minutos atrás, Basole disse:

@Boudais eu só fiz um teste de formatação condicional, e aparentemente, esta ok.

 

Faça outros testes com seus critérios para ver se esta correto.

RGB-FormatCond R0-v6.zip

Excelente solução!!!!

  • Curtir 1
Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!