ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Column widths to adjust automatically? (https://www.excelbanter.com/excel-discussion-misc-queries/4334-column-widths-adjust-automatically.html)

lambola

Column widths to adjust automatically?
 
How do I get column widths to automatically adjust depending on the size of
text entered in a cell ?

Jimbola

The only way to do it would be to use a change event macro.
With the workbook open press Alt+F11, this take you to the visual basic
editor.
In the left double click the worksheet where you want the code.
Past the following code.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim r As Range

'Set range, so we are looking for text entered in A1:A500, change this as
needed.
Set r = Intersect(Range("A1:A5"), Target)

'If the change in the worksheet is not detected, exit the macro.
If r Is Nothing Then Exit Sub

'If text is entered do autofit on the column
Columns("A:A").EntireColumn.AutoFit



End Sub


"lambola" wrote:

How do I get column widths to automatically adjust depending on the size of
text entered in a cell ?



All times are GMT +1. The time now is 05:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com