I'm trying to copy a filtered table to another worksheet. I only want to copy the filtered rows, but I also want the formulas to reference the new table, not the old table.
From what I've seen, the only to copy formulas from one table to a new table correctly is to use [tt]PasteSpecial Paste:=xlPasteAll[/tt], but, if I use that, it copies ALL the rows, not just the filtered rows.
Here's my code, which copies all the rows. I've tried using other [tt]Paste:=[xlWhateverIsThere][/tt] but it doesn't work. The formulas reference the old table.
[tt]
Public Sub create_archive_table()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim wb As Workbook
Dim lo As ListObject
Dim s1 As String, s2 As String
s1 = "project_list"
s2 = "project_archive"
Set wb = ThisWorkbook
Set ws1 = wb.Sheets(s1)
Set lo = ws1.ListObjects("tblProjects")
Sheets.Add(After:=Sheets(s1)).Name = s2
Set ws2 = wb.Sheets(s2)
wb.SlicerCaches("Slicer_status").SlicerItems("Canceled").Selected = True
wb.SlicerCaches("Slicer_status").SlicerItems("Complete").Selected = True
lo.Range.SpecialCells(xlCellTypeVisible).Copy
With ws2.Range("A1")
.PasteSpecial Paste:=xlPasteAll
' .PasteSpecial Paste:=xlPasteFormulasAndNumberFormats
' .PasteSpecial Paste:=xlPasteValuesAndNumberFormats
' .PasteSpecial Paste:=xlPasteValues
' .PasteSpecial Paste:=xlPasteFormulas
' .PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
.Select
End With
Application.CutCopyMode = False
Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
Set lo = Nothing
End Sub
[/tt]
Thanks!!
Matt
From what I've seen, the only to copy formulas from one table to a new table correctly is to use [tt]PasteSpecial Paste:=xlPasteAll[/tt], but, if I use that, it copies ALL the rows, not just the filtered rows.
Here's my code, which copies all the rows. I've tried using other [tt]Paste:=[xlWhateverIsThere][/tt] but it doesn't work. The formulas reference the old table.
[tt]
Public Sub create_archive_table()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim wb As Workbook
Dim lo As ListObject
Dim s1 As String, s2 As String
s1 = "project_list"
s2 = "project_archive"
Set wb = ThisWorkbook
Set ws1 = wb.Sheets(s1)
Set lo = ws1.ListObjects("tblProjects")
Sheets.Add(After:=Sheets(s1)).Name = s2
Set ws2 = wb.Sheets(s2)
wb.SlicerCaches("Slicer_status").SlicerItems("Canceled").Selected = True
wb.SlicerCaches("Slicer_status").SlicerItems("Complete").Selected = True
lo.Range.SpecialCells(xlCellTypeVisible).Copy
With ws2.Range("A1")
.PasteSpecial Paste:=xlPasteAll
' .PasteSpecial Paste:=xlPasteFormulasAndNumberFormats
' .PasteSpecial Paste:=xlPasteValuesAndNumberFormats
' .PasteSpecial Paste:=xlPasteValues
' .PasteSpecial Paste:=xlPasteFormulas
' .PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
.Select
End With
Application.CutCopyMode = False
Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
Set lo = Nothing
End Sub
[/tt]
Thanks!!
Matt