LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Filter and select the upmost rows

Hi Gary

Below is my table, when i filter for business it should copy only the five
rows.

Item Total Name Name

business 1 a
sales 2 b
scraps 3 c
business 1 a
sales 2 b
scraps 3 c
business 1 a
sales 2 b
scraps 3 c
business 1 a
sales 2 b
scraps 3 c
business 1 a
sales 2 b
scraps 3 c
business 1 a
sales 2 b
scraps 3 c
business 1 a
sales 2 b
scraps 3 c
business 1 a
sales 2 b
scraps 3 c
business 1 a
sales 2 b
scraps 3 c

"Gary''s Student" wrote:

This small macro will copy the header row and the first 5 visible rows. For
test purposes I pasted in A100:

Sub copyfilter()
k = 0
Set r = Nothing
For i = 1 To Rows.Count
If Cells(i, 1).EntireRow.Hidden = True Then
Else
If r Is Nothing Then
Set r = Cells(i, 1)
Else
Set r = Union(r, Cells(i, 1))
End If
k = k + 1
If k = 6 Then Exit For
End If
Next
r.EntireRow.Copy Range("A100")
End Sub
--
Gary''s Student - gsnu200781


"Ranjit kurian" wrote:

Hi

I have three columns (Item, Total, Name), the below code goes to item column
then put autofilter, after that selects Business from the item column , item
column contains Business, Sales, Scrapes etc..., till here its working fine
after this i need the macro to select and copy the first five rows only.

Actually when you put autofilter to select Business, few columns like sales
, scrapes etc.. column will be hidden , which i do't need when iam selected
Business, and the range also differ always..

Sub test()
Range("A1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="Business"
Range("A1:C1").Select

' copy only five rows

End Sub

 
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
Excel data filter collapses rows even after I select show all!?!?!? [email protected] Excel Discussion (Misc queries) 4 January 9th 07 12:42 PM
Select all from filter alvin Kuiper Excel Programming 3 May 4th 06 09:04 AM
Filter/Select multiple rows a_moron Excel Discussion (Misc queries) 5 January 20th 06 02:41 PM
"Criteria Range" in the "Data/Filter/Advanced Filter" to select Du TC Excel Worksheet Functions 1 May 12th 05 02:06 AM
Select from/filter ten Excel Programming 0 August 12th 03 08:40 AM


All times are GMT +1. The time now is 07:14 PM.

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"