Gentle VBA prank

DarthWilbur

New Member
Joined
Feb 23, 2012
Messages
0
Hey all,

I'm looking at putting a VBA prank in a colleague's xlsm.

Basically I want a macro that monitors for any changes in the text in cells B:B. (This could be blank to not blank, or not blank to different not blank)

If any changes are made it will delete the new text and replace it with a custom message. (The custom message can be the same every time).

Does anyone know how to do this?

Cheers,
Darth Wilbur
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Thanks, Hiker.
But I did see that thread earlier. It doesn't help with what I'd like to achieve.
 
Not that I would condone such practices, but possibly as a worksheet_change event

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
Target.Value = "Stop Changing These Cells"
End If

End Sub
 
Such an important application should really turn events off to stop the code triggering itself and include some error handling ;-)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    On Error GoTo ErrorHandler
    Application.EnableEvents = False

    If Target.Column = 2 Then
        Target.Value = "Stop Changing These Cells"
    End If

CleanExit:
    Application.EnableEvents = True
    Exit Sub

ErrorHandler:
    MsgBox Err & " - " & Err.Description
    GoTo CleanExit

End Sub

Dom
 
That should be Resume CleanExit rather than GoTo CleanExit, yes yes? ;)
 
Thank you,SteveO59L, Domski and Colin Legg!

Works perfectly!
Looking forward to getting a confused query from target.coworker today. :)
 

Forum statistics

Threads
1,223,754
Messages
6,174,314
Members
452,554
Latest member
Louis1225

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