+ Reply to Thread
Results 1 to 3 of 3

Multilple selection delete issue

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-15-2012
    Location
    Jamaica
    MS-Off Ver
    Microsoft 365
    Posts
    244

    Multilple selection delete issue

    I have a code that works fine, if I click on a cell and click delete its fine; however if I highlight more than one cell and press delete it triggers the messagebox in the code and sends the message in a loop.

    Note: in some cases it doesnt throw the messagebox, it actually gives a run time error, I am not seeing the error now but it refers to type mismatch.


    Can anyone tell me what is causing that?

    below is the code i am having the issue with:


     
    Private Sub Worksheet_Change(ByVal Target As Range)
     
    
    If Not Application.Intersect(Target, Range("$a$8:$a$3000")) Is Nothing Then
    On Error Resume Next
               With CreateObject("vbscript.regexp")
                .Global = True
                .Pattern = "[^0-9C.]"
                If .test(Target.Value) Then
                    MsgBox "The ACCOUNT number field is restricted to numbers only (0 - 9)"
                    Target.Clear
                    Target.Select
                End If
            End With
        End If

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Multilple selection delete issue

    When you program an Events procedure like this, you have to disable EVENTS in order for the event not call itself in loop

    You have to put this line of code at the beginning of your macro:
    Application.EnableEvents = False
    and you MUSt re-enable the events before the macro ends with this line of code:
    Application.EnableEvents = True
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Forum Contributor
    Join Date
    09-15-2012
    Location
    Jamaica
    MS-Off Ver
    Microsoft 365
    Posts
    244

    Re: Multilple selection delete issue

    Thank you so much it worked very well. Wow!! and to think the answer was that simple, you all bright people make people like us feel silly!

    Quote Originally Posted by p24leclerc View Post
    When you program an Events procedure like this, you have to disable EVENTS in order for the event not call itself in loop

    You have to put this line of code at the beginning of your macro:
    Application.EnableEvents = False
    and you MUSt re-enable the events before the macro ends with this line of code:
    Application.EnableEvents = True

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1