ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable range of rows (https://www.excelbanter.com/excel-programming/349933-re-variable-range-rows.html)

Dave Peterson

Variable range of rows
 
So you can copy the visible rows elsewhere???

Option Explicit
Sub testme()
Dim RngToCopy As Range

With Worksheets("Sheet1")
With .AutoFilter.Range
Set RngToCopy = Nothing
On Error Resume Next
Set RngToCopy = .Resize(.Rows.Count - 1, .Columns.Count) _
.Offset(1, 0).Cells.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
End With

If RngToCopy Is Nothing Then
'no visible rows--except the header
Else
RngToCopy.Copy _
Destination:=Worksheets("sheet2").Range("a1")
End If

End Sub

It copies the details--not the header.

Dirk wrote:

Can someone help me with the following :
In a macro I use autofilter for columns A to I.
This range of columns doesn't change. But the rows do. Sometimes there
are 80 rows, sometimes there are 200 or even more rows.
How can I realise this in a macro ?
Many thanks for your reply.

--
Dirk
------------------------------------------------------------------------
Dirk's Profile: http://www.msusenet.com/member.php?userid=6449
View this thread: http://www.msusenet.com/t-1873649102


--

Dave Peterson


All times are GMT +1. The time now is 08:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com