Forum Discussion

nzingha417's avatar
nzingha417
Copper Contributor
Jun 18, 2023
Solved

How to permanently fix column width

Each time I open up my excel file, the columns revert back to a smaller size. I have to widen the columns each time that I open the file. How do I permanently expand the file and save it to avoid having to widen the columns each time I re-open the file?  Thank you

  • nzingha417 

    If you are using Office 2019 and working with a CSV file, the column width settings cannot be directly saved within the CSV file itself. However, you can use a workaround by following these steps:

    1. Open the CSV file in Excel.
    2. Adjust the column widths as desired by dragging the column dividers or using the AutoFit feature to fit the content.
    3. Select all the cells in the worksheet by clicking the "Select All" button at the top left corner of the worksheet (or pressing Ctrl+A).
    4. Right-click on any of the selected cells and choose "Copy" from the context menu.
    5. Create a new Excel workbook by clicking "File" > "New Workbook" or pressing Ctrl+N.
    6. In the new workbook, right-click on cell A1 and choose "Paste" > "Keep Source Formatting" or press Ctrl+Alt+V. This will paste the content, including the adjusted column widths, from the CSV file into the new workbook.
    7. Finally, save the new workbook as an Excel file (.xlsx) by clicking "File" > "Save As" and choosing a location on your computer.

    By following these steps, you will have a new Excel file with the adjusted column widths saved. Whenever you open this file, the columns should remain the same width as you set them.

    Please note that this workaround involves copying the content from the CSV file into a new Excel file. Any formulas, formatting, or data validation rules that were present in the original CSV file may not be preserved in the new Excel file.

5 Replies

  • NikolinoDE's avatar
    NikolinoDE
    Platinum Contributor

    nzingha417 

    Since there is no information about which Excel version it is, which operating system or storage medium. I'm assuming it's Excel 2016 and Windows 10...But it also fits other versions.

    Why? because there are no details!

    Welcome to your Excel discussion space!

     

    Suggested solutions:

    To permanently fix the column width in Excel and ensure that it remains the same when you reopen the file, you can follow these steps:

    1. Open your Excel file.
    2. Select the column or columns that you want to adjust the width for. To select multiple columns, hold down the Ctrl key while clicking on each column header.
    3. Once the columns are selected, right-click on any of the selected column headers and choose "Column Width" from the context menu.
    4. In the Column Width dialog box, enter the desired width for the columns and click "OK". You can specify the width in characters or pixels.
    5. After adjusting the column width, go to the "File" tab in the Excel ribbon and click on "Save" or press Ctrl+S to save your changes.

    By following these steps, the column width settings will be saved with the Excel file, and when you reopen it, the columns should remain the same width as you set them.

    Note: If you want to apply the same column width settings to multiple Excel files, you can create a template file with the desired column width and use it as a basis for new files. Simply save the template file and use it as a starting point whenever you need to create a new Excel file.

     

    How to AutoFit in Excel: adjust columns and rows to match data size

    How to change column width and AutoFit columns in Excel

     

    Option with VBA code:

     

    Option Explicit 
     
    Sub SetColumns() 
         '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         ' Purpose:      Autofit columns but make sure not less than default minimum width
         ' Assumption:   The preferred minimum column width has been previously set, so the
         '               procedure should make the column wider if required, but not skinnier
         '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         
        Dim rng As Range ' cells in heading range
        Dim sngWidth As Single ' default width of column
         
         
        For Each rng In Range(Range("A1"), Range("IV1").End(xlToLeft)) 
             
            sngWidth = Columns(rng.Column).ColumnWidth 
             
            rng.EntireColumn.AutoFit 
             
             ' reset column if it is skinnier than the original width
            If Columns(rng.Column).ColumnWidth < sngWidth Then 
                Columns(rng.Column).ColumnWidth = sngWidth 
            End If 
        Next rng 
    End Sub 
    ' Code from http://www.vbaexpress.com

     

    How to use:

    1. Open Excel
    2. Open the VBE window by pressing [Alt-F11]
    3. Select Insert | Module
    4. Copy the code above and paste it into the module
    5. Press [Alt-F4] to close the VBE window

    Test the code:

    1. Copy all data rows in the sheet "Data"
    2. Paste the data into cell A2 of the "Template" sheet
    3. Select Tools | Macro | Macros
    4. Double-click on "SetColumns"
    5. Check that all data is displayed correctly, and no headings have strange text wrapping
    6. Select column D on the "Template" sheet
    7. Select Format | Column | Width
    8. Type "11" and press [Enter]
    9. Select Tools | Macro | Macros
    10. Double-click on "SetColumns"
    11. Note the width of column D

    Sample File:Insert

      • NikolinoDE's avatar
        NikolinoDE
        Platinum Contributor

        nzingha417 

        If you are using Office 2019 and working with a CSV file, the column width settings cannot be directly saved within the CSV file itself. However, you can use a workaround by following these steps:

        1. Open the CSV file in Excel.
        2. Adjust the column widths as desired by dragging the column dividers or using the AutoFit feature to fit the content.
        3. Select all the cells in the worksheet by clicking the "Select All" button at the top left corner of the worksheet (or pressing Ctrl+A).
        4. Right-click on any of the selected cells and choose "Copy" from the context menu.
        5. Create a new Excel workbook by clicking "File" > "New Workbook" or pressing Ctrl+N.
        6. In the new workbook, right-click on cell A1 and choose "Paste" > "Keep Source Formatting" or press Ctrl+Alt+V. This will paste the content, including the adjusted column widths, from the CSV file into the new workbook.
        7. Finally, save the new workbook as an Excel file (.xlsx) by clicking "File" > "Save As" and choosing a location on your computer.

        By following these steps, you will have a new Excel file with the adjusted column widths saved. Whenever you open this file, the columns should remain the same width as you set them.

        Please note that this workaround involves copying the content from the CSV file into a new Excel file. Any formulas, formatting, or data validation rules that were present in the original CSV file may not be preserved in the new Excel file.

Resources