Column widths to adjust automatically?

G

Guest

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

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top