+ Reply to Thread
Results 1 to 2 of 2

Excel Crashes if I Delete a Row

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Oxford
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    120

    Exclamation Excel Crashes if I Delete a Row

    Hey All,

    I have a Work book that works really well until i try to Delete a Row. If I do it Frezes Excel. it works fine befor i added some code. is there anything i can do to stop my code from running if cells are deleted or is there anything wrong with my code making this happern??

    here is the code and i have also attaced the worksheet with the code it as well

    Private Sub WorkSheet_change(ByVal Target As Range)
    
    Application.ScreenUpdating = False
    
        If Target.Cells.Count > 1 Or IsEmpty(Target) Or Not Target.Column = 2 Then Exit Sub
        
    Dim BC_ERROR As Double
    
    Let BC_ERROR = Target.Row
    
        If Cells(BC_ERROR, 3).Value = "" Then
    
            MsgBox prompt:="INVALID BARCODE", Buttons:=vbOKOnly + vbInformation
            Target.Cells.Value = ""
            Target.Cells.Select
            ActiveSheet.Protect
            Application.ScreenUpdating = True
            Exit Sub
    
        End If
    
        If IsNumeric(Target) Then
    
            ActiveSheet.Unprotect
        
            Dim LROW As Double
        
         Let LROW = Sheets("SALE_INVOICE").Range("B65536").End(xlUp).Row
        
                Range(Cells(LROW, 2), Cells(LROW, 19)).Select
                Selection.Copy
                Cells(LROW + 2, 2).Insert
                Application.CutCopyMode = False
            
            ActiveSheet.Spinners(ActiveSheet.Spinners.Count).LinkedCell = Cells(LROW + 2, 13).Address
        
                Cells(LROW + 2, 12) = 0
                Cells(LROW + 2, 13) = 51
                Cells(LROW + 2, 2) = ""
                Cells(LROW + 2, 2).Select
            
        Else
    
            MsgBox prompt:="INVALID BARCODE", Buttons:=vbOKOnly + vbInformation
            Target.Cells.Value = ""
            Target.Cells.Select
        
        End If
    
    TextBox6.Text = Format(Sheets("SALE_INVOICE").Range("S2").Value, "Currency")
    TextBox4.Text = Format(Sheets("SALE_INVOICE").Range("AC3").Value, "Short Time")
    ActiveSheet.Protect
     Application.ScreenUpdating = True
        
    End Sub
    Thanks

    Tom
    Attached Files Attached Files

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Excel Crashes if I Delete a Row, FRUSTRATING

    You could try setting Application.EnableEvents equal to false at the start of your code and back to true at the end to avoid the macro firing again when you are making changes with the code.
    Martin

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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