Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default how to select rows after autofilter

The following commands make a part of macro I'm trying to complete

Selection.AutoFilter Field:=24, Criteria1:="="
Rows("10:1186").Select
Selection.Delete Shift:=xlUp

The first line specifies an autofilter and a criteria that generates
an output typical of the autofilter function.

This next two commands selects and deletes all the rows (and then some
for good measure, hence the 1186) that need to be deleted. These lines
were generated during a "record macro", hence the explicit 10:1186.

Now it is expected that the starting row to delete will not always be
row 10 due to the variability of the content of the rows before the
filter is applied (well duh!)

So, my question is, how is the filter output more generically selected
so that all any rows from the filter output result will be deleted?

Thanks for any suggestions!

John Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default how to select rows after autofilter

I think you can use looping to delete the row one by one.

Sub DeleteBlank()
Application.ScreenUpdating = False
Dim i As integer, lastrow As integer
lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = lastrow To 2 Step -1
With Worksheets("Sheet1").Range("X" & i)
If .Value = "" Then
.EntireRow.Delete
End If
End With
Next
End Sub

"John Keith" wrote:

The following commands make a part of macro I'm trying to complete

Selection.AutoFilter Field:=24, Criteria1:="="
Rows("10:1186").Select
Selection.Delete Shift:=xlUp

The first line specifies an autofilter and a criteria that generates
an output typical of the autofilter function.

This next two commands selects and deletes all the rows (and then some
for good measure, hence the 1186) that need to be deleted. These lines
were generated during a "record macro", hence the explicit 10:1186.

Now it is expected that the starting row to delete will not always be
row 10 due to the variability of the content of the rows before the
filter is applied (well duh!)

So, my question is, how is the filter output more generically selected
so that all any rows from the filter output result will be deleted?

Thanks for any suggestions!

John Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default how to select rows after autofilter

On Fri, 29 Aug 2008 00:06:00 -0700, leungkong
wrote:

Leungkong,

Thank you for your reply.

I need to ask some questions so I can understand all the details of
your suggestion.

Was this Sub intended to operate on the filtered output or are you
suggesting replacing the autofilter command completely with this Sub?

I assume I could put this code in line with my existing code rather
than having it be a separate Sub?

I think you can use looping to delete the row one by one.

Sub DeleteBlank()
Application.ScreenUpdating = False
Dim i As integer, lastrow As integer
lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = lastrow To 2 Step -1
With Worksheets("Sheet1").Range("X" & i)
If .Value = "" Then
.EntireRow.Delete
End If
End With
Next
End Sub

"John Keith" wrote:

The following commands make a part of macro I'm trying to complete

Selection.AutoFilter Field:=24, Criteria1:="="
Rows("10:1186").Select
Selection.Delete Shift:=xlUp

The first line specifies an autofilter and a criteria that generates
an output typical of the autofilter function.

This next two commands selects and deletes all the rows (and then some
for good measure, hence the 1186) that need to be deleted. These lines
were generated during a "record macro", hence the explicit 10:1186.

Now it is expected that the starting row to delete will not always be
row 10 due to the variability of the content of the rows before the
filter is applied (well duh!)

So, my question is, how is the filter output more generically selected
so that all any rows from the filter output result will be deleted?

Thanks for any suggestions!

John Keith



John Keith

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default how to select rows after autofilter

On Fri, 29 Aug 2008 00:06:00 -0700, leungkong
wrote:

I think you can use looping to delete the row one by one.


Leungkong,

Thank you for your recommendation. This weekend I finally implemented
your suggestion and it worked great. For the number of rows I need to
delete the looping does not take significant time.


John Keith

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default how to select rows after autofilter

Create a range object and assign the filtered rows to that, in this case it
is deleted.

Dim rng2 as Range, wShData as Worksheet
Set wShData = ActiveWorkbook.Worksheets("Sheet1")

With wShData.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng2 Is Nothing Then rng2.EntireRow.Delete
End With


--

Regards,
Nigel




"John Keith" wrote in message
...
The following commands make a part of macro I'm trying to complete

Selection.AutoFilter Field:=24, Criteria1:="="
Rows("10:1186").Select
Selection.Delete Shift:=xlUp

The first line specifies an autofilter and a criteria that generates
an output typical of the autofilter function.

This next two commands selects and deletes all the rows (and then some
for good measure, hence the 1186) that need to be deleted. These lines
were generated during a "record macro", hence the explicit 10:1186.

Now it is expected that the starting row to delete will not always be
row 10 due to the variability of the content of the rows before the
filter is applied (well duh!)

So, my question is, how is the filter output more generically selected
so that all any rows from the filter output result will be deleted?

Thanks for any suggestions!

John Keith




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default how to select rows after autofilter

Nigel,

Thank you also for your suggestion.

Like the other response to my inquiry I need to better understand how
this works.

I assume the Dim and Set commands need to be located early in my
macro?

Then the With loop lines are located after the filter command?

Sometimes usenet messages have lines broken in unintended locations.
Was the Set rng2... line and the next line .SpecialCells.....
supposed to be one line?

I have no idea what is being done in the set rng2 row. Is there a
reference you can point me to in order to get an understanding of what
is being done?

I assume the .SpecialCells(xlCellTypeVisible) is identifying the
visible data that remains after the filter command?


On Fri, 29 Aug 2008 08:22:23 +0100, "Nigel"
wrote:

Create a range object and assign the filtered rows to that, in this case it
is deleted.

Dim rng2 as Range, wShData as Worksheet
Set wShData = ActiveWorkbook.Worksheets("Sheet1")

With wShData.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng2 Is Nothing Then rng2.EntireRow.Delete
End With


John Keith

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default how to select rows after autofilter

On Fri, 29 Aug 2008 08:22:23 +0100, "Nigel"
wrote:

Create a range object and assign the filtered rows to that, in this case it
is deleted.


Nigel,

I also tried your suggestion this weekend and it worked fine, but I
still don't have a good understanding of how it works. Thanks for the
suggestion.


John Keith

Reply
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
Select cells after Autofilter Haris Excel Worksheet Functions 2 October 28th 07 09:48 PM
Scroll home after Autofilter select Steve Excel Programming 3 August 1st 07 12:24 AM
Select first field whilst autofilter is on bony_tony Excel Programming 1 May 4th 07 03:58 AM
autofilter, command to select filtered range? matthias Excel Programming 1 October 16th 06 11:28 AM
Autofilter - on select columns rudawg Excel Worksheet Functions 8 January 31st 06 06:20 AM


All times are GMT +1. The time now is 12:31 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"