jadams0173
Technical User
- Feb 18, 2005
- 1,210
Using Excel 2000.
I've been trying for the past few hours to use VBA to turn on an autofilter, copy the records it returns to a new sheet at the next unused row. Then clear the contents(not delete) the records from the original sheet. I've been searching a lot through this fora and found some help after I recorded my inital macro.
Also is there a way to not copy the column labels when coping the auto filter contents.
I've been trying for the past few hours to use VBA to turn on an autofilter, copy the records it returns to a new sheet at the next unused row. Then clear the contents(not delete) the records from the original sheet. I've been searching a lot through this fora and found some help after I recorded my inital macro.
Also is there a way to not copy the column labels when coping the auto filter contents.
Code:
Sub Macro5()
Dim uCol [COLOR=blue]As[/color] [COLOR=blue]Long[/color]
Dim uRow [COLOR=blue]As[/color] [COLOR=blue]Long[/color]
Dim myRange [COLOR=blue]As[/color] [COLOR=blue]Range[/color]
Sheets("WIP").Select
Cells(1, 1).Select
Application.CutCopyMode = [COLOR=blue]False[/color]
Selection.AutoFilter
Selection.AutoFilter Field:=4, Criteria1:="Complete"
uCol = ActiveSheet.UsedRange.Columns.Count
[COLOR=red]' uRow = ActiveSheet.UsedRange.Rows.Count
[/color] uRow = Application.WorksheetFunction.Subtotal(3, [COLOR=#FF00FF]Range[/color]("a1", "a50"))
[COLOR=red]'Range(Cells(10, 1), Cells(uRow, uCol)).Select
[/color]
[COLOR=red]' Selection.Copy
[/color] [COLOR=blue]Set[/color] myRange = Selection.CurrentRegion.SpecialCells(xlCellTypeVisible)
myRange.Copy
Sheets("Complete").Select
uRow = ActiveSheet.UsedRange.Rows.Count
[COLOR=red]'should be last used cell + 1 so A and some variable
[/color] [COLOR=#FF00FF]Range[/color]("A" & uRow).Select
ActiveSheet.Paste
[COLOR=red]' Range("G5").Select
[/color] Application.CutCopyMode = [COLOR=blue]False[/color]
ActiveSheet.PivotTables("PivotTable3").RefreshTable
Sheets("WIP").Select
Selection.ClearContents
Selection.Interior.ColorIndex = 2
Selection.AutoFilter Field:=4
Selection.AutoFilter
[COLOR=#FF00FF]Range[/color]("A1").Select
[COLOR=blue]End[/color] Sub