简体   繁体   中英

how to Highlight cells value based on another cells value

I'm working on a macro that highlighted & colors the empty cells in a specific column (AE), but I need to clear this color-highlighted based on a result that exists in the column (AD)

If AD column, cells value = "SPLICE" clear color, If Empty the color should exist, below picture explains more. I use the code below

Sub EmptyTerminalTO()

Application.ScreenUpdating = False

Sheets("Wire List").Activate
Dim i As Long
Dim c As Long
Dim myRange As Range
Dim myCell As Range

Set myRange = Range("AD2", Range("AD" & Rows.Count).End(xlUp))

For Each myCell In myRange '
    c = c + 1
    If (myCell) = "" Then
        myCell.Interior.Color = RGB(255, 87, 87)
        i = i + 1
    End If
Next myCell

Rapport8 = i

 Application.ScreenUpdating = True
 
End Sub

在此处输入图像描述

try using offset as per code below:

Option Explicit

Sub EmptyTerminalTO()

Application.ScreenUpdating = False

Sheets("Wire List").Activate
Dim i As Long
Dim c As Long, Rapport8 As Long
Dim myRange As Range
Dim myCell As Range

Set myRange = Range("AD2", Range("AD" & Rows.Count).End(xlUp))

For Each myCell In myRange '
    c = c + 1
    If (myCell) <> "SPLICE" Then
        myCell.Offset(0, 1).Interior.Color = RGB(255, 87, 87)
    Else
        myCell.Offset(0, 1).Interior.Pattern = xlNone
    i = i + 1
    End If
Next myCell

Rapport8 = i

 
End Sub

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