Forum Discussion

HenryVIII's avatar
HenryVIII
Copper Contributor
Jan 27, 2019

Automatic column sizing

Is there a function key that will allow one to  paste new column headings over existing column headings and have the system automaitically  adjust the column width to match the new headings?  If not is their a workaround that accomplishes the same task without having to manually change the column width?

 

Thanks...

2 Replies

  • MobeeDick's avatar
    MobeeDick
    Copper Contributor
    Highlight the entire column at the top, then Double tap (double click). It will automatically "right size"
  • Haytham Amairah's avatar
    Haytham Amairah
    Silver Contributor

    Hi Henry,

     

    You need to a special solution using a VBA code.

     

    Hover the Mouse over the worksheet tab, right-click, and select (View Code).

    Then copy and paste the below code into the worksheet code module.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Cells.Columns.AutoFit
    End Sub

     

    After that, save the workbook as (*.xlsm) to retain the code in it.

    Please note that this code applies only to the sheet in which this code is saved.

     

    Hope that helps

Resources