Why has 'Code Exectution has been interuppted?"

spcalan

Well-known Member
Joined
Jun 4, 2008
Messages
1,247
Please take a look at this code.
Why is is stopping and throwing an error?

the Blue End if is where it stops, ( for no good reason ).


Private Sub Format()
Application.EnableEvents = False
Application.ScreenUpdating = False

With Sheets("Sheet1")
FR = 2
LR = .Cells(Rows.Count, "A").End(xlUp).Row

'New Headers
.Range("A1:Q1") = Array("Customer", "City", "State", "Order #", "PO #", "Type", "Pro #", "Cases", "Pounds", "WHS", "Carrier", "Promise Date", "Ship Date", "Status", "Header Hold", "Detail Hold", "In Database")

'Delete Closed or Cancelled Orders
For x = LR To FR Step -1
If .Cells(x, "N") <> "OPEN" Then
.Rows(x).EntireRow.Delete
End If
Next x

'Delete On Hold Orders
For x = LR To FR Step -1
If .Cells(x, "O") <> 0 Or .Cells(x, "P") <> 0 Then
.Rows(x).EntireRow.Delete
End If
Next x

'Convert Order# to Number
Columns("D:D").Select
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True

'Enter Vlookup's
.Range("Q" & FR & ":Q" & LR).Formula = "=IF(ISERROR(VLOOKUP(D2,Database!D:E,2,FALSE)),""NO"",VLOOKUP(D2,Database!D:E,2,FALSE))"

'Copy/Paste Vlookup Results
Columns("Q:Q").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Please take a look at this code.
Why is is stopping and throwing an error?

the Blue End if is where it stops, ( for no good reason ).


Private Sub Format()
Application.EnableEvents = False
Application.ScreenUpdating = False

With Sheets("Sheet1")
FR = 2
LR = .Cells(Rows.Count, "A").End(xlUp).Row

'New Headers
.Range("A1:Q1") = Array("Customer", "City", "State", "Order #", "PO #", "Type", "Pro #", "Cases", "Pounds", "WHS", "Carrier", "Promise Date", "Ship Date", "Status", "Header Hold", "Detail Hold", "In Database")

'Delete Closed or Cancelled Orders
For x = LR To FR Step -1
If .Cells(x, "N") <> "OPEN" Then
.Rows(x).EntireRow.Delete
End If
Next x

'Delete On Hold Orders
For x = LR To FR Step -1
If .Cells(x, "O") <> 0 Or .Cells(x, "P") <> 0 Then
.Rows(x).EntireRow.Delete
End If
Next x

'Convert Order# to Number
Columns("D:D").Select
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True

'Enter Vlookup's
.Range("Q" & FR & ":Q" & LR).Formula = "=IF(ISERROR(VLOOKUP(D2,Database!D:E,2,FALSE)),""NO"",VLOOKUP(D2,Database!D:E,2,FALSE))"

'Copy/Paste Vlookup Results
Columns("Q:Q").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With
End Sub

It starts on the last row ( 9824 ) and does the deleting and stops on Row 8799 for some reason?
 
Upvote 0
I tested the bit of loop code and it works fine.

is column A filled out always? no blanks ?
 
Upvote 0
I tested the bit of loop code and it works fine.

is column A filled out always? no blanks ?

Yes. ColA is always filled..
This code works for a certain amount of time ( rows ), but stops for no good reason?

I can run VBA again, and it will pick up where it left off and then stop after 300-400 rows.
 
Upvote 0
quite odd indeed.

What if you add

Application.EnableCancelKey = xlDisabled

to the top of the macro?
 
Upvote 0
Here are some more ideas....

You should put an Option Explicit statement at the top of your code module and declare all of your variables:
Code:
Option Explicit
 
 
Private Sub Format()
Dim FR As Long
Dim LR As Long
Dim x As Long
 
'etc...
If you don't declare them then they are auto-initialised as variants. Occassionally variant types can cause this kind of behaviour.


Have you named any procedures or modules in the project with an Excel keyword?



In addition to shyrath's suggestion,
Code:
application.EnableCancelKey = xlDisabled


you can also try these remedies:
  1. Check that no keys on your keyboard are stuck
  2. Check your mouse is OK.
  3. Try rebooting your computer.
  4. Try exporting/importing modules, including any add-ins or personal.xls.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,046
Members
449,063
Latest member
ak94

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