View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chris Chris is offline
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,