Cell border created with macro seems to be fixed to cell=ignores filter

Veronika Dicerova 0 Reputation points
2023-02-13T08:01:51.8+00:00

Dear all,

A tried to substitute conditional formatting function by writing a code. It seemed to be working, except one issue. After sorting the columns the cell border does not move with the original cell values. The CellBorder remains on the original cell, however the cell fill color seems to be moving. Is there something that could fix it?

Thank you!

Veronika

used code:

Sub conditional_formatting_on_metrics()

Dim xCell As Range

Dim CommentValue As String

Dim CommentRange As Range

Set CommentRange = Range("G:G")

For Each xCell In CommentRange

CommentValue = xCell.Value

Select Case CommentValue

Case "Red"

xCell.Interior.Color = RGB(192, 0, 0)

Case "LightGreen"

xCell.Interior.Color = RGB(226, 239, 218)

Case "Green"

xCell.Interior.Color = RGB(112, 173, 71)

End Select

Next xCell

Set CommentRange = Range("H:I")

For Each xCell In CommentRange

CommentValue = xCell.Value

Select Case CommentValue

Case "Red"

xCell.Interior.Color = RGB(192, 0, 0)

Case "Red Warning"

xCell.Interior.Color = RGB(237, 125, 49)

xCell.Borders.LineStyle = Excel.XlLineStyle.xlContinuous

xCell.Borders.Color = RGB(192, 0, 0)

Case "Amber Warning"

xCell.Interior.Color = RGB(226, 239, 218)

xCell.Borders.LineStyle = Excel.XlLineStyle.xlContinuous

xCell.Borders.Color = RGB(237, 125, 49)

Case "Green"

xCell.Interior.Color = RGB(112, 173, 71)

End Select

Next xCell

End Sub

User's image

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,956 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,979 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.