Auto Expand Columns

JVID

New Member
Joined
Jan 9, 2013
Messages
39
How do I make columns auto expand without having to double click the column?

JV
 
Is this permanent?
It will be if you save the workbook.

Or did you mean will the column always autofit from thereon out? If that is your question, the answer is no, but if you want, we can develop VB event code for you that will automatically autofit any columns you want to have that feature... just tells us that you want VB code and also tell us which columns should have the feature.
 
Upvote 0
I need it fixed. I have a template that I will use and for every change in the template some of the items have larger $'s then others.

Any insight into the code? How can we start that?

Thanks,

JV
 
Upvote 0
Hi,
I am not an expert. So try this on a copy of the data.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Set Target = Columns("A:Z")
ActiveCell.EntireColumn.AutoFit

End Sub

Jai
 
Upvote 0
I need it fixed. I have a template that I will use and for every change in the template some of the items have larger $'s then others.

Any insight into the code? How can we start that?
What columns do you want to have this auto-fit feature?
 
Upvote 0
Columns D, G and J
Give this event code a try...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Col As Range
  If Not Intersect(Target, Range("D:D,G:G,J:J")) Is Nothing Then
    For Each Col In Intersect(Target, Range("D:D,G:G,J:J")).Columns
      Col.EntireColumn.AutoFit
    Next
  End If
End Sub
HOW TO INSTALL Event Code
------------------------------------
If you are new to event code procedures, they are easy to install. To install it, right-click the name tab at the bottom of the worksheet that is to have the functionality to be provided by the event code and select "View Code" from the popup menu that appears. This will open up the code window for that worksheet. Copy/Paste the event code into that code window. That's it... whenever you type something in Column D, G or J, the column will be resize to fit the longest entry in that column.
 
Upvote 0
Sorry for the delay, can I put this at the bottom of an existing macro within VBA?

Thanks,

John
 
Upvote 0

Forum statistics

Threads
1,226,852
Messages
6,193,366
Members
453,792
Latest member
Vic001

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