formatting cells

ockie

New Member
Joined
Jan 11, 2020
Messages
36
Office Version
  1. 2013
Platform
  1. Windows
Hi,
seeking help on my following problem
I am trying to color a cell eg A1. if there is a value in B1, C1 etc A1 will turn yellow. but as soon as there is no value in a cell eg D1 A1 reverts to normal. In summary A1 will be highlighted as long as the is a value in B1:Z1
thanks robert
 
Try this:

VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrTrap

    Dim i As Long, j As Long

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    'If the entry just made is within columns N to AG (inclusive), then...
    If Target.Column >= 14 And Target.Column <= 33 Then
        '...check each row and if there are no blanks from Col. N up and including the column where the entry was just made (up to Col. AG), then...
        j = Range("N:AG").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        For i = 1 To j
            If Evaluate("COUNTA(N" & i & ":" & Split(Target.Address, "$")(1) & i & ")") = (Target.Column - 14) + 1 Then
                '...colour Col. D of the row just updated yellow
                Range("D" & i).Interior.Color = vbYellow
            'Else...
            Else
                '...remove the fill colour from Col. D of the row just updated as there's a gap of data being entered sequentially
                Range("D" & i).Interior.Color = xlNone
            End If
        Next i
    End If
 
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
  
Exit Sub

ErrTrap:

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub
Thanks Trebor, it works just as I had envisioned, I just needed someone with a lot more knowledge of VBA to assist, again thank you very much for your assistance it is very much appreciated.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top