Compile Error Next without For

Will85

Active Member
Joined
Apr 26, 2012
Messages
254
Office Version
  1. 365
Platform
  1. Windows
Hello,

Another board member provided me with this VBA but has since vanished, leaving me with an error. I am teaching myself about loops (pretty cool!), but still cant figure out what is missing. I get a compile error, with the first Next highlighted. But I think its the start of the code that's wrong, not the end? But I am still just learning about loops.
Code:
Sub DeleteRowsandComboboxes()
    Dim Cel As Range
    Dim Shp As Shape
    Dim ro As Integer
    Set Cel = Cells(1, 1)
    
    Do Until Cel.End(xlDown).Row = 1048576
    Set Cel = Cel.End(xlDown)
        ro = Cel.Row
        If Cel = "Yes" Then
            Rows(ro).Delete
            Set Cel = Cells(ro, 1)
        Else
            Set Cel = Cel.End(xlDown)
        End If
    Next
    
    For Each Shp In ActiveSheet.Shapes
        If Shp.Type = 8 Then
            Shp.Select
            If Selection.LinkedCell = "#REF!" Then Shp.Delete
        End If
    Next


End Sub
 
Last edited by a moderator:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
did you have a working version, as for why you are testing a million rows, i'm sure it can be pulled back inline. how many rows usually involved
 
Upvote 0
I dont have a working version. i noticed that too, I think he just assumed to test all rows. in reality I can make an assumption that it would never surpass 500 rows (probably much lower than that if it needs to be, but 500 just to be safe)
 
Upvote 0
many formulas, they can recalculate every time you change a line, so would normally work up, rather than down
 
Upvote 0
Not sure I follow. This macro would only be run at the users discretion and probably rarely.
 
Upvote 0
some formulas are volatile, so recalculate every sheet change, and deleting a line would be such a trigger, if you had 500 rows of volatile formulas that does take time
 
Upvote 0
Ok. Well Im still no closer to understanding the compile error . . . .
 
Upvote 0
I'm not certain but you have Do Loop and For Next, and we seem to have Do Next
 
Upvote 0
Ok. Well if your not certain, and Im not certain, I guess were not getting anywhere.
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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