VBA code exits before completing

Misca

Well-known Member
Joined
Aug 12, 2009
Messages
1,749
Office Version
  1. 365
Platform
  1. Windows
I'm using Excel 2003 and my code is supposed to delete the calculations leaving just the values. Everything seems to be working like it should 'till the code is supposed to delete the original data rows / columns:
Code:
Rows("1:67").Delete Shift:=xlUp
Columns("A:AJ").Delete Shift:=xlToLeft
The code deletes the rows and never gets to the columns-part. I tried adding MsgBox between the rows just to see if it's the Columns-part that's "crashing" the code but the code never got that far.

I tried to code to another workbook and everything went smoothly. Tried running the code from the other workbook to this one and it never got to the Columns-part. Tried swithing the row order and still only the first row completes.

There are a few named ranges in the the ranges the code is supposed to delete. Could this be causing the problems? The rest of the cells to be deleted are just values used in formulas in the range that I'm trying to move closer to A1 but the formulas are already converted to values when the code gets this far.

Is this a known bug or is there just something wrong with my workbook? And how could I get around it?

Here's the whole thing:
Code:
Sub ValuesOnly()
Dim SH As Shape
Dim Alue As Range
Dim Rng As Range

'Delete macro buttons:
    For Each SH In ActiveSheet.Shapes
        SH.Delete
    Next SH
    
'Convert formulas to values:
    With Range("AK:BM")
        .Value = .Value
    End With
'Delete the extra rows and columns:
    Rows("1:67").Delete Shift:=xlUp
    Columns("A:AJ").Delete Shift:=xlToLeft
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I don't know if this will make a difference

Code:
Rows("1:67").Delete Shift:=xlShiftUp
Columns("A:AJ").Delete Shift:=xlShiftToLeft

Or you could omit the Shift argument as you are deleting entire rows and columns.
 
Upvote 0

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

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