Stop (target) Macro From Prompting To Debug

Kamolga

Well-known Member
Joined
Jan 28, 2015
Messages
1,185
Hi,

I have a a target macro that starts with

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Keycells as Range
Set KeyCells = Range("R:R,AF:AF,AT:AT,BH:BH,BV:BV,CJ:CJ,CX:CX,DL:DL")


      If Not Application.Intersect(KeyCells, Range(Target.Address)) _
                   Is Nothing Then
    
        If Range(Target.Address).Offset(0, -4).Value = KeyText Then

etc.
and does a lot of complex (to me) things perfectly as long as I select a value from the lists in the target range.

My problem is that if the user select multiple cells in the range (to delete their values only), I have an error on the last line of the shown code and the debugg screen show up.

I have googled the 3 solutions below without success:

-if target in not a single cell, exit sub
-do not show debugg screen (I tried a few online things and do not feel comfortable with it, where to put it, etc.)
-Click end on the debugg screen (does not seem possible)

Thank you in advance for your help
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi,

Have you put the Exit Sub in the right place?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim Keycells As Range
    Set Keycells = Range("R:R,AF:AF,AT:AT,BH:BH,BV:BV,CJ:CJ,CX:CX,DL:DL")

    If Not Application.Intersect(Keycells, Range(Target.Address)) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Range(Target.Address).Offset(0, -4).Value = KeyText Then
        
        
        
        
        
End Sub
 
Upvote 0
Hi,

No I did not and the formula was no right either :)

Thank you very much RickXL, that works great!
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

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