Note:
You modify the solution:
Sub change_col()
If Range("a1").Value = 3 Then
Columns("B:B").EntireColum
End If
End Sub
This auto-sizes the column to fit what ever is in there.
Main Topics
Browse All TopicsI'm new to using macros in excel and I was wondering
how do I create a macro that will allow me to expand or contract a column based on the value of a cell?
i.e.. If the cell value = 3 then expand the column if the value is not 3 then the column stays the same or contracts to its original state..
Any help would greatly be appreciated
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
click tools/macros/visual basic editor
if you want this done automatically then:
click view/project explorer
you'll see a tree view of your project
double click on sheet("The name of your worksheet here")
cut and paste this code into the big white box that appears to the right of the project explorer.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
Columns("B:B")..ColumnWidt
End Sub
click back to your worksheet on your task bar and enjoy!
the code expands column b:b 18 when a cell is changed in column b
i could modify it to any width or any (or all) columns - whatever you like
This question has been classified as abandoned. I will make a recommendation to the moderators on its resolution in the next round. I would appreciate any comments by the experts that would help me in making a recommendation.
It is assumed that any participant not responding to this request is no longer interested in its final deposition.
If the asker does not know how to close the question, the options are here:
http://www.experts-exchang
PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER
HAGD:O)Bruintje
EE Cleanup Volunteer
This question has been classified as abandoned. I will make a recommendation to the moderators on its resolution in the next round. I would appreciate any comments by the experts that would help me in making a recommendation.
It is assumed that any participant not responding to this request is no longer interested in its final deposition.
If the asker does not know how to close the question, the options are here:
http://www.experts-exchang
PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER
HAGD:O)Bruintje
EE Cleanup Volunteer
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation in the Cleanup topic area:
PAQ no refund
[question stated "contract to it's original state" this cannot be done other then saving state continously]
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
bruintje
EE Cleanup Volunteer
Business Accounts
Answer for Membership
by: esapoPosted on 2003-01-24 at 09:35:04ID: 7801752
Sub change_col() = 18.43
If Range("a1").Value = 3 Then
Columns("A:A").ColumnWidth
End If
End Sub
Here, if the value of cell A1 is 3 then the column A will expand to 18.43.
Regards