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

I'm am having an issue when trying to insert a range from an autofilter on
one sheet to another. The range has to be inserted above rows that have data
in them. When I use the insert.shift:xldown, it only moves down the first
column.

TIA,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default Insert an autofiltered range into another tab

Sub B_CreateTabs()

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


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


Windows("Mybook.xls").Activate
Sheets(shtval).Select
Sheets(shtval).Copy After:=Workbooks("Mybook.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


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

' ** start of problem code
Rows("1:" & lngLastRow).Select
Selection.Copy
Sheets(shtval).Select
Selection.Insert Shift:=xlDown
' ** end of problem code

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

End Sub




"Chris" wrote:

I'm am having an issue when trying to insert a range from an autofilter on
one sheet to another. The range has to be inserted above rows that have data
in them. When I use the insert.shift:xldown, it only moves down the first
column.

TIA,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Insert an autofiltered range into another tab


Here is what I usually do

1) Get last row of data on orignal sheet before filtering

LastRow = .range("A" & rows.count).end(xlup).row

2) Apply filters

3) Copy visibile rows using specialcellst method

Set filterData = rows("1:" &
LastRow).SpecialCells(type:=xlCellTypeVisible)

4) Copy Range

FilerData.Copy

5) No insert the rows on 2nd sheet

Sheets("sheet2").Rows(1).Insert


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=198948

http://www.thecodecage.com/forumz

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Insert an autofiltered range into another tab

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


  #5   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 11:46 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"