Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Select first 5 visible rows

I have a filtered spreadsheet and am trying to select the first 5 visible
rows to copy onto a separate sheet.

I can use ActiveCell.Offset(1,0).Select to get the next row down but how can
I move on until the next row is visible (looping?) and how can I then
continue to move down and in addition to the first selected visible row
select the next 4 visible rows? I can then paste all 5 elsewhere.
Alternatively, do I have to select each visible row individually and paste
elsewhere within the loop? If so, how do I stop the loop running after the
fifth time?

A little knowledge is a dangerous thing!

Really grateful for any assistance with this.

Paul.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Select first 5 visible rows

Dim HowManyVisRows as long
dim VisRng as range
dim myCell as range
dim iCtr as long

'apply the filter someway

With worksheets("somesheetname").autofilter.range
'subtract one for the header.
howmanyvisrows _
= .columns(1).cells.specialcells(xlcelltypevisible). cells.count - 1

if howmanyvisrows = 5 then
'avoid the header and come down one row
'and only look at one the first column
set visrng = .resize(.rows.count-1, 1).offset(1,0) _
.cells.specialcells(xlcelltypevisible)
else
set visrng = nothing
end if
end with

if visrng is nothing then
'warning message???
msgbox "not enough visible rows!
else
ictr = 0
for each mycell in visrng.cells
ictr = ictr + 1
if ictr 5 then
exit for
end if
mycell.entirerow.copy _
destination:=somewhereelse
next mycell
end if

Untested, uncompiled--watch for typos.

Paul Brown wrote:

I have a filtered spreadsheet and am trying to select the first 5 visible
rows to copy onto a separate sheet.

I can use ActiveCell.Offset(1,0).Select to get the next row down but how can
I move on until the next row is visible (looping?) and how can I then
continue to move down and in addition to the first selected visible row
select the next 4 visible rows? I can then paste all 5 elsewhere.
Alternatively, do I have to select each visible row individually and paste
elsewhere within the loop? If so, how do I stop the loop running after the
fifth time?

A little knowledge is a dangerous thing!

Really grateful for any assistance with this.

Paul.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Select first 5 visible rows

Many thanks Dave,

I will give it a go.

"Dave Peterson" wrote in message
...
Dim HowManyVisRows as long
dim VisRng as range
dim myCell as range
dim iCtr as long

'apply the filter someway

With worksheets("somesheetname").autofilter.range
'subtract one for the header.
howmanyvisrows _
= .columns(1).cells.specialcells(xlcelltypevisible). cells.count - 1

if howmanyvisrows = 5 then
'avoid the header and come down one row
'and only look at one the first column
set visrng = .resize(.rows.count-1, 1).offset(1,0) _
.cells.specialcells(xlcelltypevisible)
else
set visrng = nothing
end if
end with

if visrng is nothing then
'warning message???
msgbox "not enough visible rows!
else
ictr = 0
for each mycell in visrng.cells
ictr = ictr + 1
if ictr 5 then
exit for
end if
mycell.entirerow.copy _
destination:=somewhereelse
next mycell
end if

Untested, uncompiled--watch for typos.

Paul Brown wrote:

I have a filtered spreadsheet and am trying to select the first 5 visible
rows to copy onto a separate sheet.

I can use ActiveCell.Offset(1,0).Select to get the next row down but how
can
I move on until the next row is visible (looping?) and how can I then
continue to move down and in addition to the first selected visible row
select the next 4 visible rows? I can then paste all 5 elsewhere.
Alternatively, do I have to select each visible row individually and
paste
elsewhere within the loop? If so, how do I stop the loop running after
the
fifth time?

A little knowledge is a dangerous thing!

Really grateful for any assistance with this.

Paul.


--

Dave Peterson



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
How to select Visible Cells range minus 2 rows (frozen panes) LuisE Excel Programming 5 November 22nd 07 05:01 AM
Show/Select Visible Rows via ComboBox notso Excel Programming 3 March 12th 07 02:34 AM
How can I select non visible cells? [email protected] Excel Programming 3 March 9th 07 02:47 PM
select only used rows and only visible cells Rokuro kubi Excel Discussion (Misc queries) 2 September 28th 06 02:06 PM
VBA to Select All Visible Sheets bill_morgan Excel Programming 4 March 1st 06 05:57 AM


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