LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Code Needed To Loop Through Certain Rows

I'm using VBA 6.5 and trying to write the code other users will initiate via
a control within a file/worksheet.

I have code that prepares imported data in a worksheet, which essentially
identifies rows that should be untouched as well as those that should be
deleted. I need to incorporate a portion of code to loop through rows 1
through 15,000 and then again through 20,000 through 25,000, and delete each
row which has the word "DELETE" in a given column of the worksheet.

I tried the code below, but since it loops through all the rows of the file,
it takes quite awhile to complete. Since this is will be excuted by front-end
users, the code needs to be added to the existing macro/control.

Question: How can I edit the code to only process through the two sets of
rows (ie 1-15,000 and then 20,000-25,000)? If this needs to be done in one
step to address the first set of rows, and a secondary step for the other set
of rows, that is fine.

Any assistance would be greatly appreciated. I do not have much experience
posting questions, so hopefully this question is being sent to the proper
group. Thank You

'DELETES ROWS PREDETERMINED TO BE DELETE-ABLE
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

Firstrow = ActiveSheet.UsedRange.Cells(1).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1

With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1

If IsError(.Cells(Lrow, "AY").Value) Then
'Do nothing, This avoid a error if there is a error in the
cell

ElseIf .Cells(Lrow, "AY").Value = "DELETE" Then
.Rows(Lrow).Delete
End If
Next
End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple loop needed please Alan Excel Discussion (Misc queries) 1 May 5th 10 06:33 PM
VB Script Code needed for Grouping Rows Abhi_Rise Excel Discussion (Misc queries) 0 February 19th 08 02:01 PM
Code needed to copy rows. QuickLearner[_19_] Excel Programming 0 July 21st 06 12:24 PM
Help needed on loop johncassell[_56_] Excel Programming 2 May 17th 06 01:05 PM
loop code needed JohnUK Excel Programming 1 June 14th 05 05:17 AM


All times are GMT +1. The time now is 11:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"