EXCEL "EntireColumn.AutoFit" Help!

F

Fred

Can anyone recommend a good Excel group (for dummies!), or maybe my
question is a simple one (by the group's collective standards). I
frequently do Format/Column/AutoFit to get my columns to fit (expand
or shrink) to fit the contents in every column, and would like to be
able to have Excel do it automatically. Someone said I could use a
Worksheet Selection Change event, like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Columns("A:IV").EntireColumn.AutoFit
End Sub

I was clueless, but took a shot in the dark and with the file open,
opened up Visual Basic, inserted a Module, copied and pasted their
text, saved and closed. It WORKED! Well, it worked at WORK anyways,
and now that I'm trying it again at home, I can't get it to work at
all. This "dummy" needs some help please! Using Microsoft Excel 2000
in Windows 2000 at work and ME at home. Thanks.
 
C

CLR

You can also "auto-fit" a single column or a group of consecutive columns
just by highlighting them and then moving the cursor to the right edge of
the rightmost selected column header, right where the cursor changes shape
and then double clicking........all highlighted columns will be
auto-fitted.........

Vaya con dios,
Chuck, CABGx3
 
T

Tom Ogilvy

you would need to right click on the sheet tab where you want this behavior
and select view code.

Paste the code into that module. There will probably be a selectionchange
event declared by default - delete that - you only need one.

this will only work on that sheet.
 
F

FredL

Tom,

Worked perfectly that way (and easier to do than the method I was
trying to use)! Now, is there an easy way to do that on ALL the sheets
in a given workbook, or would I need to copy the code then right mouse
click on each individual sheet to keep adding it?

Thanks, Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top