Autofit Column width works of first sheet but not second sheet

Gowapiti

New Member
Joined
Jun 3, 2019
Messages
4
I am trying to make my table columns autofit to width. I have the following code which works on the first sheet with Table1 but after the next sheet is copied and becomes the active sheet the next line errors out with "Application defined or object defined error" and will not autofit the columns on Sheet 2

Code:
Private Sub SAVE_QUOTE_Click()
        
Dim Quotation As Worksheet: Set Quotation = ThisWorkbook.Sheets("Quotation")
     
    ActiveSheet.Unprotect
    Quotation.Range("I4") = Quotation.Range("I4") + 1
    
    Application.DisplayAlerts = False
    
    'Copy Quote to a New Workbook
    Dim NewFN As Variant
    Dim wb As Workbook
    Set wb = Workbooks.Add
    ThisWorkbook.Sheets("Quotation").Copy After:=wb.Sheets(1)
    ActiveSheet.ListObjects(1).Range.Columns.AutoFit
    ThisWorkbook.Sheets("Internal Use Only").Copy After:=wb.Sheets(2)
    ActiveSheet.ListObjects(1).Range.Columns.AutoFit
    Set wb = Nothing
    
    Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
    'Sheets("Sheet3").Activate
      
    ActiveWindow.SelectedSheets.Delete
[\code]

The remainder of my save function works like it should, I just need to resize the columns on this 2nd sheet.

Thanks!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Works for me.
Any difference between the 2 sheets?
Executes the macro in a new book, with the leaves named "Quotation" and "Internal Use Only" each sheet with a table.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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