Setting column width, issue with code

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
I can not set the column width for column A in the new sheet, and I can not work out why. The rest of the code is fine. I have posted the whole code below. The issue is only with 1 line.

Problem with this, rest of the code works
VBA Code:
 Worksheets("Keywords Search").Column("A").ColumnWidth = 100

Full Code
VBA Code:
' Keyword sheet2 create a copy of the sheet
    Application.SheetsInNewWorkbook = 1
        Workbooks.Add
    With ThisWorkbook
        .Sheets("Sheet2").UsedRange.Copy 'Copy this sheet
            ActiveWorkbook.Sheets(1).Range("A1").PasteSpecial xlPasteValues
            ActiveWorkbook.Sheets(1).Name = "Keywords Search" ' new sheet name
  On Error Resume Next
        
[B]'' ######################## THIS BIT IS NOT WORKING ###################[/B]
   'ColumnWidths
         Worksheets("Keywords Search").Column("A").ColumnWidth = 100
   
'[B]' ######################## THIS BIT IS NOT WORKING ###################[/B]
        'Worksheets("Keywords Url Search").Columns("A:B").ColumnWidth = 700
         'Worksheets("Keywords Url Search").Columns("B:K").AutoFit
         'Worksheets("Sheet2").Columns("L:Q").ColumnWidth = 30 ' ADDRESS

'Formatting the header
        Range("A1").Font.Name = "Calibri"
            Range("A1").HorizontalAlignment = xlCenter
                Range("A1").Font.Color = vbWhite
                    Range("A1:z1").Interior.ColorIndex = 16 '''''.Color = vbGreen
 'Name of Sheet
       ActiveWorkbook.SaveAs "Keyword Search" & Format(Now, " dd_mm_yyyy    HH_mm_ss") & ".xlsx"
 On Error Resume Next

 'Freeze panel on new sheet
        Dim ws As Worksheet
            For Each ws In Worksheets
                 ws.Activate
                     With Application.ActiveWindow
                .SplitColumn = 0
            .SplitRow = 1
        End With
            Application.ActiveWindow.FreezePanes = True
                If Not ActiveSheet.AutoFilterMode Then
            ActiveSheet.Range("A1").AutoFilter   
        End If
         Next ws
    End With

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Cheers Fluff,

Originally is was "Columns" with the "S" but it would not work for some reason. I have been trying to fix it for the last hour, then I removed the "S" as I was only doing 1 column and not columns, Still nothing worked. So I decided to post. You said add and "S" and I did and it decided to work.

LOL.

I give up.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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