Macro gives message box every time something is deleted

jason90

New Member
Joined
Mar 21, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi All!

I have the below macro that used to work fantastically for me, i would have two columns, one for the keyword and one for the message i want to appear if that word is used
I would like to use it again but for some reason now when i put it into my workbook whenever i delete anything in the workbook i get a message box showing just a singular line "-"

if i remove the line of code for that message box the macro doesn't function at all, I've tried various ways of trying to get it to stop to no avail, please help!

FYI this is not my code and I'm very much an amateur at this

VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim rng As Range
Dim fnd As Range

    'Set the keyword range
    'Make sure the first column lists postcode
    'and second column with desiredinformation message
    Set rng = Range("Keywords")
   
    'DON'T enter anything apart from problems in this tab.
    'that we store the keywords
    If Sh Is rng.Worksheet Then Exit Sub
   
    'Use "Find" method to search in the first column of keyword range
    Set fnd = rng.Columns(1).Find(Target.Value, LookIn:=xlValues, LookAt:=xlWhole)
    If Not fnd Is Nothing Then
        MsgBox fnd.Cells(, 1).Value & " - " & fnd.Cells(, 2).Value, vbOKOnly + vbExclamation
    End If
End Sub
 
Last edited by a moderator:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊

My guess is that the 'Keywords' range has one or more blank rows.
 
Upvote 0
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊

My guess is that the 'Keywords' range has one or more blank rows.
thank you very much for your help, this has resolved it, i made the keywords area larger as i thought i could just add to it without having to extend it every time, is this a possibility?
 
Upvote 0
i made the keywords area larger as i thought i could just add to it without having to extend it every time, is this a possibility?
Yes, just change this line near the end
Rich (BB code):
If Len(fnd.Value) > 0 Then MsgBox fnd.Cells(, 1).Value & " - " & fnd.Cells(, 2).Value, vbOKOnly + vbExclamation
 
Upvote 0
Solution
Yes, just change this line near the end
Rich (BB code):
If Len(fnd.Value) > 0 Then MsgBox fnd.Cells(, 1).Value & " - " & fnd.Cells(, 2).Value, vbOKOnly + vbExclamation
Absolute hero, have a fantastic day!
 
Upvote 0
Glad it worked for you. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,223,840
Messages
6,174,960
Members
452,593
Latest member
Jason5710

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