Macro skips lines of script

rjunk

Board Regular
Joined
Apr 25, 2003
Messages
63
I have a macro that has a loop in it. Because I don't know what else I can use to end the loop, it is written to "End Sub" if certain criteria is met.
After the text for the loop ends, I still have a few lines of code.
Once the criteria for ending the loop is met though, the macro stops and the last few lines of script are ignored.
Any suggestions?
Below is the loop, as well as the lines that are being skipped:

Do Until ActiveCell.Row = 65536
Selection.End(xlDown).Select
Selection.ClearContents
If ActiveCell.Row = 65536 Then Exit Sub
ActiveCell.Offset(1, 0).Select
ActiveCell.EntireRow.Insert
Range("Q1").Select
Loop
Selection.AutoFilter Field:=17
Range("A1").Select
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Sure. Instead of using Exit Sub inside your loop, use Exit Do instead. This will exit your loop but still allow your code to finish.
 
Upvote 0
The help function in our excel application can tell you that. However, if you want to expand your knowledge more, just
visit this site more often and you will learn many things everyday.
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

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