Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default Insert an autofiltered range into another tab

Thank you very much. It's working.

Chris



"OssieMac" wrote:

Hi Chris,

Modified to include the column headers. Does not subtract 1 from the
numbRows and removed the offset and resize from the range to copy.

Sub B_CreateTabs()

Dim rngE As Range
Dim lngLastRow As Long
Dim mgrval, lobval, shtval As String
Dim numbRows As Long

mgrval = "myself"
lobval = "dept"
shtval = mgrval & "-" & lobval

Windows("MyWorkbook.xls").Activate
Sheets(shtval).Select
Sheets(shtval).Copy _
After:=Workbooks("MyWorkbook.xls").Sheets(1)

Sheets("Reports").Select
ActiveSheet.AutoFilterMode = False

lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row

'Apply the filter
ActiveSheet.Range("A1:G" & lngLastRow) _
.AutoFilter Field:=3, Criteria1:=lobval

ActiveSheet.Range("A1:G" & lngLastRow) _
.AutoFilter Field:=4, Criteria1:=mgrval

'Count number of visible cells in one column.
'Includes column headers
numbRows = Sheets("Reports") _
.AutoFilter.Range.Columns(1) _
.SpecialCells(xlCellTypeVisible) _
.Cells.Count

'Insert the number of required rows starting row 2
'Includes row for column header.
Sheets(shtval).Rows(2 & ":" & 2 + numbRows - 1) _
.Insert Shift:=xlDown

'Copy the visible data including column headers
With Sheets("Reports").AutoFilter.Range
.EntireRow _
.SpecialCells(xlCellTypeVisible) _
.Copy
End With

'Paste the data starting row 2
Sheets(shtval).Rows(2).PasteSpecial

Sheets("Reports").Select
Range("A2").Select
ActiveSheet.AutoFilterMode = False

End Sub


--
Regards,

OssieMac


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
Delete some column headings from an autofiltered range. Champ Excel Worksheet Functions 1 February 17th 10 06:39 AM
Assigning AutoFiltered Range to Range Object Simon Excel Programming 5 March 11th 09 01:04 AM
Get count of duplicate strings from autofiltered range gtslabs Excel Programming 2 January 23rd 09 05:30 PM
Top of AutoFiltered Range? Dave Birley Excel Programming 2 July 6th 07 01:02 PM
empty autofiltered range Stefi Excel Programming 3 July 27th 05 03:08 PM


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