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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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.
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

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