It is working now, but it very, very slow. At least it takes 10
seconds to check the whole file.
After column DA there is nothing in...
Hope you can help me make it faster.
This is the code I now use:
Private Sub Worksheet_Activate()
Dim myCell As Range
With ActiveSheet
For Each myCell In .UsedRange.Rows(2).Cells
myCell.EntireColumn.Hidden = CBool(myCell.Value = "")
Next myCell
End With
End Sub
Thanks
Roger Govier - 03 Jul 2007 08:55 GMT
Hi
> After column DA there is nothing in...
> Hope you can help me make it faster
Dave's code is using the Used Range so it will not be going beyond
column DA if that is the last column.
Maybe you have some formulae with volatile functions, which will be
causing a lot of re-calculation.
You can turn off calculation (and screen updating) at the beginning, and
back on at the end. That will probably speed things up.
Private Sub Worksheet_Activate()
Dim myCell As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With ActiveSheet
For Each myCell In .UsedRange.Rows(2).Cells
myCell.EntireColumn.Hidden = CBool(myCell.Value = "")
Next myCell
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Signature
Regards
Roger Govier
> It is working now, but it very, very slow. At least it takes 10
> seconds to check the whole file.
[quoted text clipped - 12 lines]
>
> Thanks
Dave Peterson - 03 Jul 2007 13:03 GMT
Just to add to Roger's response...
If you can see the pagebreak dotted lines, then excel will slow down.
If you're in View|Page break preview mode, then excel will slow down.
So combining these with Roger's .screenupdating and .calculationmode changes:
Option Explicit
Sub testme()
Dim myCell As Range
Dim CalcMode As Long
Dim ViewMode As Long
Application.ScreenUpdating = False
CalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
With ActiveSheet
.DisplayPageBreaks = False
For Each myCell In .UsedRange.Rows(1).Cells
myCell.EntireColumn.Hidden = CBool(myCell.Value = "")
Next myCell
End With
'put things back to what they were
Application.Calculation = CalcMode
ActiveWindow.View = ViewMode
Application.ScreenUpdating = True
End Sub
> It is working now, but it very, very slow. At least it takes 10
> seconds to check the whole file.
[quoted text clipped - 12 lines]
>
> Thanks

Signature
Dave Peterson