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
 
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.


my only problem is that I am using this in a template macro and it doesn't take unless I hit enter. Any way to tack it into so that when the references calc it auto expands?
 
Upvote 0
my only problem is that I am using this in a template macro and it doesn't take unless I hit enter. Any way to tack it into so that when the references calc it auto expands?
Just so I understand your setup, are you saying that Columns D, G and J contain formulas and that you want the columns to resize when the cells the formulas reference get changed? If so, are all the cell referenced by the formulas on the same worksheet as the formulas themselves? If not, can you post one formula from each of your columns so that I can see what is being referenced?
 
Upvote 0
Just so I understand your setup, are you saying that Columns D, G and J contain formulas and that you want the columns to resize when the cells the formulas reference get changed? If so, are all the cell referenced by the formulas on the same worksheet as the formulas themselves? If not, can you post one formula from each of your columns so that I can see what is being referenced?


Yes. They are basic formulas (A1/b1) but I have a macro that duplicates a template and makes each template a unique worksheet therefore changing the values and making some cells needing to be larger then others.

Follow?
 
Upvote 0

Forum statistics

Threads
1,226,859
Messages
6,193,390
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