Excel VBA highlight cell in specific column when value is changed

BKPE

New Member
Joined
Jan 20, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

How to adjust below code in order to highlight a cell (only in specific columns) when value is changed?

Private Sub WorkSheet_Change(ByVal Target As Range)
If Target.Value <> "" Then
Target.Interior.ColorIndex = 36
End If
End Sub

Thanks.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

EXCEL MAX

Active Member
Joined
Nov 11, 2020
Messages
499
Office Version
  1. 2016
Platform
  1. Windows
Hello BKPE,
choose columns by column index...
VBA Code:
Private Sub WorkSheet_Change(ByVal Target As Range)

    Dim vSomeColumn As Integer, vSomeColumn2 As Integer

    vSomeColumn = 3
    vSomeColumn2 = 5
    If Target.Value <> "" And _
       Target.Column >= vSomeColumn And _
       Target.Column <= vSomeColumn2 Then
       Target.Interior.ColorIndex = 36
    End If
    
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,990
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
Another option
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("A:A,C:C,H:H")) Is Nothing Then
      If Target <> "" Then Target.Interior.ColorIndex = 36
   End If
End Sub
Change columns to suit.
 

BKPE

New Member
Joined
Jan 20, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi EXCEL MAX and Fluff,

Both options worked perfect!

Thanks a lot.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,990
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

EXCEL MAX

Active Member
Joined
Nov 11, 2020
Messages
499
Office Version
  1. 2016
Platform
  1. Windows
It's good to have more options. Thanks.
 

Forum statistics

Threads
1,144,392
Messages
5,724,081
Members
422,536
Latest member
Zeeshan53

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
Top