Change column width automatically based on data imported from another sheet/cell

shco

New Member
Joined
May 14, 2010
Messages
5
Hi

My cell A1 has the following formula:
"='SheetX'!C17"

So, if someone enters a word in cell C17 of "SheetX", that word will appear in A1.

Is it possible to have excel automatically adjust the width of column A based on the length of the word that is entered? For example, if someone enters "a very very long word" in cell C17, then column A will need to be wide. If someone enters "short" in C17, then Column A can be narrower. Is there a way I can set things so that the column width is adjusted without me having to do anything after the word is entered into C17?

Many thanks
Sam
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Right click the tab of the sheet containing that formula, sel;ect View Code and paste in

Code:
Private Sub Worksheet_Calculate()
Columns("A").AutoFit
End Sub

then press ALT + Q to close the code window.
 
Upvote 0
OR, use a Change Event on the second sheet
Code:
Private Sub Worksheet_Change(ByVal Target as Range)
If Target.Address = "$C$17" Then
   Sheet1.Columns("A").AutoFit
End If
End Sub

lenze
 
Upvote 0
Thank you very much!

I noticed that after inserting this script I've lost the ability to "undo" things in my worksheets. Is there something I can do about this?

Thanks again
Sam
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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