How to change cell width by formula ?

mrchonginhk

Well-known Member
Joined
Dec 3, 2004
Messages
679
Is it possible, without use of VBA, to increase/decrease column width ??

I was successful in increasing width using formula but fail to shrink it ...
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I'm not aware of any formula that will change the column width. Formulas can only return values. They can't perform actions.

Of course if the column is set to AutoFit, its width will increase if you enter something in a cell that won't fit the existing width. But AutoFit only works one way on data entry - upwards - unless you choose it again from the menu, or double click the boundary on the right side of the column heading.
 
Upvote 0
I was successful in increasing width using formula but fail to shrink it ...
How did you do that?
 
Upvote 0
=if(A1=1,"Loooooooooong","short")

In case A=1, column expanded. However, if A1 is set to 0 afterwards, column did not shrink...
 
Upvote 0
I think you are confused on how Excel is working. It is not the formula that tells Excel to expand the cell, it is the Autofit property. As Andrew said, formulas, in and of themselves, cannot change cell attributes (i.e. size) they can only return values. It is properties like Autofit and Wrap Text that change cell size.

Also note what Andrew said about Autofit:
Of course if the column is set to AutoFit, its width will increase if you enter something in a cell that won't fit the existing width. But AutoFit only works one way on data entry - upwards - unless you choose it again from the menu, or double click the boundary on the right side of the column heading.
That explains why you cell can grow to fit your text, but does not shrink.
 
Upvote 0
Of course we know formula did not directly change the width. We MAKE use of that to achieve what we need. However it is only half way success. Any other think out of box solution ??
 
Upvote 0
However it is only half way success. Any other think out of box solution ??
Yes, use VBA. You can make it AutoFit columns after every cell entry.

I can't think of any other way other than to use VBA.
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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