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:
did you replace the first NEXT and use a LOOP ?
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
yes, and it still didnt work, but I have a solution for the find and delete rows.

Now I am struggling to get the delete combobox code to work, nothing happens when I run it and the combobox is still on the sheet.
 
Upvote 0
is the combo in a cell, then .range("cell").clear
 
Upvote 0
This appears to be the solution I need, working so far.

Sub DeleteRowsandComboboxes()
ActiveSheet.Unprotect
On Error Resume Next
With Range("C5:C" & Cells(Rows.Count, "C").End(xlUp).Row)
.Replace "YES", "#N/A", xlWhole, , False, , False, False
.SpecialCells(xlConstants, xlErrors).EntireRow.Delete
End With
Dim OleObj As OLEObject
For Each OleObj In ActiveSheet.OLEObjects
With OleObj
If .progID = "Forms.ComboBox.1" And .LinkedCell = "#REF!" Then OleObj.Delete
End With
Next OleObj
ActiveSheet.Protect
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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