LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy Filtered Rows

I am using Autofilter programmatically to filter a database spreadshee
and then using a modified CopyFilter routine by Tom Ogilvy to copy th
rows to a TempSheet which is then copied and transposed to ViewShee
for user viewing.

The problem is not all of the rows are copied from TempSheet t
ViewSheet. I realize I may not need TempSheet to act as an intermediar
- but I'm not sure how to avoid it ... yet.

Here is Toms original code...

Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData

End Sub


and my modified code...

Sub CopyFilter()
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
Worksheets("TempSheet").Cells.Clear
Worksheets("ViewSheet").Cells.Clear
If rng2 Is Nothing Then
'MsgBox "No data found"
Else
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(0, 0).Resize(rng.Rows.Count).Copy _
Destination:=Worksheets("TempSheet").Range("A1")
End If
Worksheets("TempSheet").Select
Selection.Copy
Sheets("ViewSheet").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone
SkipBlanks:= _
False, Transpose:=True
Worksheets("Total_Hardware").Select
ActiveSheet.ShowAllData
Worksheets("ViewSheet").Select
Cells(22, 1).Value = "Back To"
Cells(22, 1).Font.Bold = True
Cells(22, 1).HorizontalAlignment = xlCenter
LinkText = "Summary!A1"
ActiveSheet.Hyperlinks.Add Anchor:=Cells(22, 2), _
Address:="", _
SubAddress:=LinkText
TextToDisplay:="Summary"
Cells(22, 2).Font.Bold = True
Cells(22, 2).HorizontalAlignment = xlCenter
End Sub

Any help is appreciated ! Thanks

--
Message posted from http://www.ExcelForum.com

 
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
Copy to filtered blank rows from another spreadsheet Juan Excel Discussion (Misc queries) 0 April 28th 10 07:59 PM
Copy and Paste Format in filtered rows XLFanatico Excel Discussion (Misc queries) 6 July 24th 09 05:53 PM
print or copy filtered rows ADIB Excel Discussion (Misc queries) 2 February 20th 09 10:48 PM
How do I copy filtered rows in excel BMX19 Excel Discussion (Misc queries) 1 June 3rd 05 12:27 AM
Copy filtered rows to a new worksheet Richmont Excel Programming 1 April 19th 04 06:34 PM


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