Re: Delete rows in a sequence

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thank you so much Rick, it worked perfectly!

I can recognize the first bad row as it is an empty row
The last of the 12 rows is also empty, but there is one other empty
row between the first and the last. If that makes sense.


On Jun 1, 1:51 pm, "Rick Rothstein"
<rick.newsNO.S...@xxxxxxxxxxxxxxxxxx> wrote:
The 12 bad rows don't always start on the same row among files, but
once the sequence starts, it is consistent for the entire sheet.

Ideally, I'd like to be able to place my cursor on the first row that
needs to be deleted, then have a macro do the rest.

Just out of curiosity, how do you recognize which row your bad data starts
on? If you can describe, in detail, how you recognize this first row of bad
data (or, perhaps alternately, the last row of "good" data before the first
row of bad data), then maybe we can include code to duplicate that process
so that you wouldn't have to select a cell on that row before running the
macro.

--
Rick (MVP - Excel)

"Rick Rothstein" <rick.newsNO.S...@xxxxxxxxxxxxxxxxxx> wrote in message

news:OHYjYiv4JHA.4272@xxxxxxxxxxxxxxxxxxxxxxx



Make any cell on the first "Bad" row of data active and then run this
macro...

Sub DeleteTwelveBadRows()
 Dim X As Long, BeginRow As Long, FinalRow As Long, LastRow As Long
 BeginRow = Selection(1).Row
 LastRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
                                  SearchDirection:=xlPrevious).Row
 FinalRow = BeginRow + 64 * ((LastRow - BeginRow + 1) \ 64) - 64
 For X = FinalRow To BeginRow Step -64
   ActiveSheet.Rows(X).Resize(12).Delete
 Next
End Sub

NOTE: Be *very* careful about activating a cell on the bad row... actions
performed by VB code **cannot** be undone.

Oh, and yes, that backward slash is correct... do *not* change it to a
forward slash... the backward slash is an operator that performs integer
division.

--
Rick (MVP - Excel)

"MostlyClueless" <casa...@xxxxxxxxx> wrote in message
news:36569b27-7b8e-4d58-86f2-d5bb58babe76@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
It seems like it should be simple to do, but I can't figure it out, so
I'm asking for help.

I've got multiple Excel files with at least 20,000 rows of data. In
each of the files, the data follows a specific sequence.

There will be 12 rows of data that need to be deleted, then 52 rows of
good data I don't want to touch, then 12 rows of data that need to be
deleted, then 52 rows of good data, etc down to the bottom of the
sheet.

The 12 bad rows don't always start on the same row among files, but
once the sequence starts, it is consistent for the entire sheet.

Ideally, I'd like to be able to place my cursor on the first row that
needs to be deleted, then have a macro do the rest. Is that possible?
I tried recording a macro, but had bad results when trying to use the
macro across sheets (it would delete the wrong rows).

Thank you for any help or suggestions!

Dan

.



Relevant Pages

  • Re: Delete rows in a sequence
    ... The only "issue" I've encountered is the macro does not delete the ... header rows followed immediately by data-filled rows (with no hidden, empty ... Rick ... it is consistent for the entire sheet. ...
    (microsoft.public.excel)
  • Re: Delete rows in a sequence
    ... Microsoft MVP Excel ... once the sequence starts, it is consistent for the entire sheet. ... I tried recording a macro, but had bad results when trying to use the ...
    (microsoft.public.excel)
  • Re: Going To The Last Empty Row and Pasting Special (Values).
    ... But can you devise a "complete" procedue as to reach the first empty row ... Dim myLastRow as Long ... and pasting the data being selected and copied from the other sheet. ... RUN MACRO ...
    (microsoft.public.excel.programming)
  • Delete rows in a sequence
    ... I've got multiple Excel files with at least 20,000 rows of data. ... once the sequence starts, it is consistent for the entire sheet. ... I tried recording a macro, but had bad results when trying to use the ...
    (microsoft.public.excel)
  • Re: Macro to validate is cell is not empty and copy the line
    ... I would like to run a macro to validate if the cell is not empty and ... I have Sheet 1 and Sheet 2 ... I would like run a macro to check if Sheet2 F3 is empty. ...
    (microsoft.public.excel.programming)