Help with VBA worksheet change event.

G0dsreaper

New Member
Joined
Jan 14, 2021
Messages
6
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
I want a worksheet change event to only take affect when anywhere in Column H the word "Cancelled" is found. I would like it change the fill of the range (A:H) of the target row red and change the font to white with a strike through. I have had this sort of work with my current sheet but I get an error every time I run my macro that adds another set of data from another sheet. If Hit end of this error, nothing happens and the code works as intended when I select the word "Cancelled" from the drop down menu.
The other issue I am having is that if I accidently choose "cancelled" instead of one of the other words in the drop down menu, I cant change the formatting back without doing it manually. Is there a way around this? Can someone help me out?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
172
Hi

Does this do what you want?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim c As Range

Endrow = Range("H" & Rows.Count).End(xlUp).Row

For Each c In Range("H1:H" & Endrow)
  If c.Value = "Cancelled" Then
     c.EntireRow.Interior.ColorIndex = 3
     c.EntireRow.Font.Color = vbWhite
     c.EntireRow.Font.Strikethrough = True
  Else
     c.EntireRow.Interior.ColorIndex = xlColorIndexNone
     c.EntireRow.Font.Color = vbBlack
     c.EntireRow.Font.Strikethrough = False
  End If
Next
   
End Sub

Edit: Missed the strikethrough part. Now added.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,549
Messages
5,636,933
Members
416,953
Latest member
prakashkumar

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