Consulting

Results 1 to 3 of 3

Thread: Stop code without ESC key

  1. #1
    VBAX Regular
    Joined
    Nov 2005
    Location
    Jefferson City
    Posts
    13
    Location

    Stop code without ESC key

    I'm using this code to copy and paste some data. I've got 11 different areas to copy and paste based on the cell value of B7. I tried a Select Case but unsuccessful so I've turned to "IF". My problem now is the code doesn't stop copying and pasting unless I hit the ESC button. I have put this code in the Change event of the worksheet, I believe it happened in the Selection_Change event as well. Any clues as to why?
    [vba]
    If Sheet1.Cells(7, 2).Value = "Bear Creek Valley GC" Then

    Range("B41:J42").Copy
    Range("B12:J13").PasteSpecial (xlPasteAll)
    Range("L41:t42").Copy
    Range("L12:t13").PasteSpecial (xlPasteAll)
    Exit Sub

    End If
    [/vba]

    WOW! it's great to be back on the board. Took a vacation from Excel for a while.


    Thanks
    I'm here to help! cmyers1032@aol.com

  2. #2
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    the selection_change is triggered by the procedure itself everytime you paste.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Precede your code with

    [vba]

    On Error GoTo ws_exit:
    Application.EnableEvents = False
    [/vba]

    and afterwards add

    [vba]

    ws_exit:
    Application.EnableEvents = True
    [/vba]

Posting Permissions

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