View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
childofthe1980s childofthe1980s is offline
external usenet poster
 
Posts: 122
Default removing rows but not based on a range

Fortunately, I figured this out on my own. For your reference, here is the
code:

I had to (a) arrow down to the cell A2 before filtering out "Grand" and (b)
do Shift-Ctrl-End for both the "Grand" and "#VALUE!" criteria. That way, VBA
does not reference specific cells!

This is all I needed! Merry Christmas to All and, after having worked on
this all day, to All a Goodnight!!!!!!!

Selection.AutoFilter
Range("A2").Select
Selection.AutoFilter Field:=1, Criteria1:="Grand"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.EntireRow.Delete
'Selection.AutoFilter Field:=1, Criteria1:="Grand"
'Rows("623:623").Select
'Selection.Delete Shift:=xlUp
Selection.AutoFilter Field:=1, Criteria1:="#VALUE!"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.EntireRow.Delete
Selection.AutoFilter Field:=1

"Mike H" wrote:

You're taking that, personally.


No I'm not, like everyone else who attempts to provide solutions here I'm
trying to help. Notwithstanding the additional information you've provided,
I'll ask again,did you try the 'second' version of my code I posted in your
other thread? What result did you get?

Mike

"childofthe1980s" wrote:

You're taking that, personally.

But, to answer your question, when I used your code I got the same results
as if I had never used your code in the first place.

So, I found a workaround through autofiltering. And, since the topic is
slightly different, I thought that I could start a new thread here and get
some help in this newsgroup without being accosted.

"Mike H" wrote:

I've given you an answer in my modified code in your other thread and if that
doesn't work a more useful description of what went wrong would be helpful

"childofthe1980s" wrote:

Because, you never can tell on these newsgroups who is available and who is
not. Truthfully, how was I to know that you were still available?

In any case, I have this situation whittled down to this last little bit.
If I can find anybody who can help me modify these two lines of this last
little bit of code, then I would be all set. And, I can pursue other
interests that I have neglected for two days because of this.

childofthe1980s

"Mike H" wrote:

Why have you started another thread?

"childofthe1980s" wrote:

Hello:

Below, I have code to which I have added to a macro to remove rows that
contain either the word "Grand" or "#VALUE!" in column A.

I got this code by "cheating". Specifically, I mimicked the use of Excel's
Auto Filtering in a macro.

This is the last piece of a very big puzzle that I have spent over two days
working on. (I did not realize that this would take so long.)

What I need to end this (hopefully once and for all) is to remove the two
ranges that are mentioned in the code below. You see, I need for this
filtering to remove rows meeting the "Grand" and "#VALUE!" criteria that I
mentioned earlier in this posting. You see, I don't have a specific range in
mind. I just need for Excel to use in its auto filtering in the code below
to remove rows at the end of my spreadsheet that say either "Grand" or
"#VALUE!" in cells in column A.

Right now, as you can see from the code below, "Grand" appears in row A667
while "#VALUE!" appears beginning in row A668. Next time, though, this data
may appear in A800, A450, A900, Awhatever.....I don't have a set range in
mind.

I don't know VBA syntax very well, but I'm guessing that it's just a matter
of taking out "("A668:D668")" and ("A667:D667") and replacing these two lines
of the code with whatever syntax that says "any row meeting this criteria".

Any help would be much appreciated!

Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="#VALUE!"
Range("A668:D668").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.EntireRow.Delete
Selection.AutoFilter Field:=1, Criteria1:="Grand"
Range("A667:D667").Select
Selection.EntireRow.Delete
Selection.AutoFilter Field:=1
Cells.Select
Selection.Copy
Sheets("Sheet3").Select
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("A1").Select
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit