Macro skips lines of script :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Macro skips lines of script
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

rjunk
Board Regular


Joined: 26 Apr 2003
Posts: 17


Status: Offline

 Reply with quote  

Macro skips lines of script

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
_________________
~Ray

Post Fri Sep 19, 2003 2:25 pm 
 View user's profile Send private message Visit poster's website

Chitosunday
Board Master


Joined: 14 Jul 2003
Posts: 423

Flag: Philippines

Status: Offline

 Reply with quote  

Instead of exit sub use "exit do"
_________________
Mr Young at Heart - Learning is like chasing the wind, it's boundless.

Post Fri Sep 19, 2003 2:28 pm 
 View user's profile Send private message Send e-mail MSN Messenger

TommyGun
MrExcel MVP


Joined: 10 Dec 2002
Posts: 3397
Location: Clear Lake, TX
Flag: Usa

Status: Offline

 Reply with quote  

Re: Macro skips lines of script

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.

Post Fri Sep 19, 2003 2:29 pm 
 View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

rjunk
Board Regular


Joined: 26 Apr 2003
Posts: 17


Status: Offline

 Reply with quote  

You guys are great.
Any suggestions as to where/how to learn this stuff?
_________________
~Ray

Post Fri Sep 19, 2003 2:31 pm 
 View user's profile Send private message Visit poster's website

Chitosunday
Board Master


Joined: 14 Jul 2003
Posts: 423

Flag: Philippines

Status: Offline

 Reply with quote  

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.
_________________
Mr Young at Heart - Learning is like chasing the wind, it's boundless.

Post Fri Sep 19, 2003 2:41 pm 
 View user's profile Send private message Send e-mail MSN Messenger
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.