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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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
 
Upvote 0
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.
 
Upvote 0
Hi EXCEL MAX and Fluff,

Both options worked perfect!

Thanks a lot.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,214
Members
448,874
Latest member
b1step2far

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