Need VBA help renaming table created when tab was copied

hinesgg

New Member
Joined
Jul 11, 2012
Messages
30
I'm using Excel 2010 in Windows 8. I have a spreadsheet with a table that contains hyperlinks. I need to create multiple versions of the data. I was unable to find any info that showed Excel would allow me to create a pivot table and carry the hyperlinks over to the pivot, so I'm taking a different approach. I'm creating macro (I'm not a scriptwriter so I typically use the mouse to record and then modify the code as needed). The macro (1) copies the tab and creates a new tab, (2) renames the tab, (3) recolors the tab, (4) renames the table, (5) filters the data, and then (6) prints. Everything works fine while I'm creating the macro. I then save the workbook, delete the newly created sheets, and try to run the macro again, but I get this MVB error: Run-timer error '9': Subscript out of range. The debugger stops on this line: ActiveSheet.ListObjects("Solicita").Name = "Solicitations". Here's my code:
HTML:
Sub NewTabsandPrint()
'
' NewTabsandPrint Macro
'
'
    Sheets("ALL").Select
    Sheets("ALL").Copy Before:=Sheets(1)
    Sheets("ALL (2)").Select
    Sheets("ALL (2)").Name = "Solicitations"
    Sheets("Solicitations").Select
    With ActiveWorkbook.Sheets("Solicitations").Tab
        .Color = 15773696
        .TintAndShade = 0
    End With
    Range("A2").Select
    ActiveSheet.ListObjects("Solicita").Name = "Solicitations"
    ActiveSheet.ListObjects("Solicitations").Range.AutoFilter Field:=4, _
        Criteria1:="=Combined Synopsis/ Solicitation", Operator:=xlOr, Criteria2 _
        :="=Solicitation"
    Sheets("ALL").Select
    Sheets("ALL").Copy Before:=Sheets(2)
    Sheets("ALL (2)").Select
    Sheets("ALL (2)").Name = "Presolicitations"
    Sheets("Presolicitations").Select
    With ActiveWorkbook.Sheets("Presolicitations").Tab
        .Color = 15773696
        .TintAndShade = 0
    End With
    Range("A2").Select
    ActiveSheet.ListObjects("Presolic").Name = "Presolicitations"
    ActiveSheet.ListObjects("Presolicitations").Range.AutoFilter Field:=4, _
        Criteria1:="Pre Solicitation"
    Sheets("ALL").Select
    Sheets("ALL").Copy Before:=Sheets(3)
    Sheets("ALL (2)").Select
    Sheets("ALL (2)").Name = "Sources Sought"
    Sheets("Sources Sought").Select
    With ActiveWorkbook.Sheets("Sources Sought").Tab
        .Color = 15773696
        .TintAndShade = 0
    End With
    Range("A2").Select
    ActiveSheet.ListObjects("SourcesS").Name = "SourcesSought"
    ActiveSheet.ListObjects("SourcesSought").Range.AutoFilter Field:=4, _
        Criteria1:="Sources Sought"
    Sheets("Solicitations").Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
    Sheets("Presolicitations").Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
    Sheets("Sources Sought").Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,223,104
Messages
6,170,125
Members
452,303
Latest member
c4cstore

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top