Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I may have spoke too soon...I copied the code to other worksheets and it does
not work. Not sure what I am doing wrong? Any ideas? "OssieMac" wrote: Hi Tim, Try the following Private Sub Worksheet_Change(ByVal Target As Range) Dim isect As Range Dim ws As Worksheet Set isect = Application.Intersect _ (Target, Columns("G:H")) If Not isect Is Nothing Then Me.Application.ActiveWorkbook.RefreshAll For Each ws In Worksheets ws.Columns("G:H").AutoFit Next ws 'Not sure if you still want the following On Error Resume Next Target.Dependents.EntireColumn.AutoFit End If End Sub If you want to exclude any sheets then use the following code in the loop. You can expand the if statement if more than one sheet to excleude. For Each ws In Worksheets If ws.Name < "MyShtToExclude" Then ws.Columns("G:H").AutoFit End If Next ws -- Regards, OssieMac "Tim" wrote: Hi there, The code below works great ... BUT ... I need it to apply to only columns G and H ...PLUS ... I would like to make this across the 25 worksheets I have. Any ideas? Thanks very much. Private Sub Worksheet_Change(ByVal Target As Range) Me.Application.ActiveWorkbook.RefreshAll Target.EntireColumn.AutoFit On Error Resume Next Target.Dependents.EntireColumn.AutoFit End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Column Autofit | Excel Discussion (Misc queries) | |||
Column AutoFit C API | Excel Programming | |||
how to autofit column widths | New Users to Excel | |||
Column Autofit | Excel Programming | |||
Column Autofit Problem | Excel Programming |