EXCEL "EntireColumn.AutoFit" Help!

  • Thread starter Thread starter Fred
  • Start date Start date
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.
 
That code would only affect one worksheet in the workbook so it's not the
best answer. To have it work on all sheets in the workbook open the
"ThisWorkbook" module for the workbook in the VBE's Project window and paste
in this code:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Sh.Columns.AutoFit
End Sub
 
Back
Top