Sunday, 1 April 2018

Set Width of Multiple Column in Excel


I have a bunch of columns on a worksheet, these columns do not have the same width, But all these columns must have in total a given width. How can I do that, keeping the ratio?


So I have this:


enter image description here


Let's now say that I want this to be 15 cm, How can I do it keeping the ratio, without having to set manually each column width?


Thanks,



Answer



Your best bet may be a VBA subroutine (a.k.a. a macro).  Here’s a kludgy proof-of-concept:



Sub resize_columns()
Columns("A").ColumnWidth = Columns("A").ColumnWidth * (15 / 10.5)
Columns("B").ColumnWidth = Columns("B").ColumnWidth * (15 / 10.5)
Columns("C").ColumnWidth = Columns("C").ColumnWidth * (15 / 10.5)
Columns("D").ColumnWidth = Columns("D").ColumnWidth * (15 / 10.5)
End Sub

I’m sure somebody here can improve on the above.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...