Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Recording a macro

I am trying to select the top 10 rows of a filtered list and then paste the
values into a temporary worksheet. I have tried several ways of recording a
macro that will do this but without success.
Currently the line of code that is selecting the range reads
"Range("A1:E11").Select". What should this read to always be the top ten
rows of a filtered list?

Thanks
Tony


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Recording a macro

Option Explicit

Sub CopyFiltered()
Dim ws As Worksheet
Dim wb As Workbook
Dim source As Range

Set ws = ActiveSheet
Set source = ws.Cells.SpecialCells(xlCellTypeVisible)
source.Copy
Set wb = Workbooks.Add
Set ws = wb.ActiveSheet
ws.Range("A1").PasteSpecial xlPasteValues
End Sub
"Ant" wrote in message
...
I am trying to select the top 10 rows of a filtered list and then paste the
values into a temporary worksheet. I have tried several ways of recording
a macro that will do this but without success.
Currently the line of code that is selecting the range reads
"Range("A1:E11").Select". What should this read to always be the top ten
rows of a filtered list?

Thanks
Tony



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Recording a macro

If you want the first 10 visible rows in the Autofiltered List

Sub ABC()
Dim rng As Range, cell As Range
Dim cnt As Long
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
cnt = 0
For Each cell In rng
If cell.Row < 1 Then
If cell.EntireRow.Hidden = False Then
cnt = cnt + 1
End If
End If
If cnt = 10 Then
rng.Resize(cell.Row).Copy Destination:= _
Worksheets("Sheet2").Range("A1")
Exit For
End If
Next
End Sub

If you use a filter of "Top 10" so you want to copy all visible rows then it
would just be:

Sub ABC()
Activesheet.AutoFilter.Range.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End Sub

--
Regards,
Tom Ogilvy

"Ant" wrote in message
...
I am trying to select the top 10 rows of a filtered list and then paste

the
values into a temporary worksheet. I have tried several ways of recording

a
macro that will do this but without success.
Currently the line of code that is selecting the range reads
"Range("A1:E11").Select". What should this read to always be the top ten
rows of a filtered list?

Thanks
Tony




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
recording a macro Heela Excel Worksheet Functions 2 September 19th 07 08:40 PM
Recording a macro Sharon New Users to Excel 1 March 21st 07 08:23 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM
Macro recording grahamp Excel Programming 2 March 31st 05 01:13 PM


All times are GMT +1. The time now is 12:35 PM.

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

About Us

"It's about Microsoft Excel"