Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

How to change Colum Width in automatically in Excel

Hey, Folks! I want to colum width automatically in my excel sheet looks like this

in my excel sheet looks like this

and I want to change look like this

and I want to change look like this

auto fill

I save this but I close the excel and I open never change

question from:https://stackoverflow.com/questions/65901867/how-to-change-colum-width-in-automatically-in-excel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. I would advise saving the document as the Excel-macro one .xslm.

  2. Next open Developer and select Visual Basic. If you don't have the one, customize your ribbon: https://wellsr.com/vba/excel/enable-developer-tab/

  3. In the VBA Excel project find the sheet you are working on

  4. Provide the VBA code like this:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Columns("C").ColumnWidth = 15
    
    End Sub
    

https://docs.microsoft.com/en-us/office/vba/api/excel.range.columnwidth

Every time you open this sheet it should be as wide as you defined in the code.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...