Well-used simple macro suddenly goes wrong

martnal

New Member
Joined
Feb 10, 2006
Messages
26
EXcel 2003. I run a macro each day as I have for many months, on a large sheet, 15,000 rows, 50 columns. It just reformats the text, changes the width of columns, adds a bit of conditional formatting etc., nothing sophisticated. The sheet is generated overnight from a SQL database.

Yesterday the macro stopped, 'Code Execution hs been interrupted.' I selected 'Continue' and all was OK. Today it was interrupted several times as above, but still ran OK. Clearly something is wrong, but I've no idea what. The first interruption is on the line below, .Name = "Courier"

This is the first dozen or so lines. Any help will be most welcome. The highlighted line changes the font from Arial to Courier.

ActiveWindow.DisplayGridlines = True
'
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Cells.Select
With Selection.Font
.Name = "Courier"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You can make this code faster by not selecting rows, columns and cells:

Code:
ActiveWindow.DisplayGridlines = True
'
Rows("1:1").Delete Shift:=xlUp
With Cells.Font
    .Name = "Courier"
    .Size = 10
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
End With


And it would make your code more concise, if not much quicker, if you don't specify all the default parameters:

Code:
ActiveWindow.DisplayGridlines = True
'
Rows("1:1").Delete Shift:=xlUp
With Cells.Font
    .Name = "Courier"
    .Size = 10
End With
 
Upvote 0
Andrew, thank you, that seems to have fixed the problem. Could you explain what it actually does, and give me any idea what caused this problem to occur?

Martin
 
Upvote 0
Andrew, thank you, that seems to have fixed the problem. Could you explain what it actually does, and give me any idea what caused this problem to occur?

Martin

It prevents the code from being interrupted by pressing Esc or Ctrl+Break. The problem is quite common but I have never seen a cause given.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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