Adjust column with VBA

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Hi, all<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Is any vba that can adjust column with according text entered.<o:p></o:p>
<o:p></o:p>
Thankx<o:p></o:p>
Moti<o:p></o:p>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
do you mean width (rather than with) ?

Code:
Sub Column_Adjust()
Columns(2).AutoFit
End

the above would adjust column B to fit the text within.

Always worth remembering that for tasks like this the macro recorder will normally show you how to achieve your goal -> ie press record, do what you want to do manually, stop recording -- review the resulting code. This will often give you what you need for a trivial task and if not it will most likely point you in the right direction.
 
Upvote 0
Hello, lasw10<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
Really I need some Private Sub function I think that allow to fit automatically as you write text long or short.<o:p></o:p>
But in the macro I have to run to get Result.<o:p></o:p>
<o:p></o:p>
Thanks Moti
 
Upvote 0
You could use something like the below but it's not very elegant...this will fire every time you change cell selection...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Columns(Target.Column).AutoFit
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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