Set Column Width to a Cell Value

indianspring

New Member
Joined
Apr 19, 2008
Messages
22
I have a macro that I need to change column width of cells depending on a cell value.

As in if cell a1 = 1.11, a2=2.22, a3=3.33, I want the width of column b to be changed to 1.11 (a1) etc..

The problem is that a1,b1 and c1 will constantly be changing which is why I cant just set the solumn width values in the macro.

Thanks in advance for any help

HTML:
Columns("B:B").Select
    Range("B2").Activate
    Selection.ColumnWidth = 31

I need 31 for example to equal whatever value is in cell a1.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
That's not too clear.:eek:

But if you want to use a cell value for a column width.
Code:
Range("B:B").ColumnWidth = Range("A1")
Or perhaps this is what you are after.
Code:
Range("B:B").ColumnWidth = Range("A1").ColumnWidth
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,573
Members
449,089
Latest member
Motoracer88

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