#1   Report Post  
ditchy
 
Posts: n/a
Default workbook macro help

Hello there, I would like some help with a macro that I need to run in
a workbook. this is the macro.
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Columns("A:Z").EntireColumn.AutoFit
End Sub
what or how do I get it to work for every worksheet in the workbook, I
currently place the macro in each worksheet which is very time
consuming. Is there a way to place the macro in the workbook so all
worksheets have the autofit macro?
regards
Ditchy

  #2   Report Post  
KL
 
Posts: n/a
Default

Hi ditchy,

Try putting the following code into the ThisWorkbook module (replace the
names of the sheets to single out as necessary).
Rgards,
KL

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
For Each s In ThisWorkbook.Worksheets
Select Case s.Name
Case "Sheet1", "Sheet2" 'Single out sheets 1 and 2.
Case Else: s.Columns("A:Z").EntireColumn.AutoFit
End Select
Next s
End Sub


"ditchy" wrote in message
ups.com...
Hello there, I would like some help with a macro that I need to run in
a workbook. this is the macro.
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Columns("A:Z").EntireColumn.AutoFit
End Sub
what or how do I get it to work for every worksheet in the workbook, I
currently place the macro in each worksheet which is very time
consuming. Is there a way to place the macro in the workbook so all
worksheets have the autofit macro?
regards
Ditchy



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
workbook macro help ditchy Excel Discussion (Misc queries) 2 December 27th 04 05:48 AM
Macro in Excel 2002 to save a workbook to a FTP location Lloyd Excel Discussion (Misc queries) 0 December 21st 04 03:49 PM
Record Macro Relative does not work? lbbss Excel Discussion (Misc queries) 1 December 13th 04 08:55 PM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 03:02 PM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 05:46 PM


All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"