Solución
Sub Macro() Application.ScreenUpdating = False ' Nuestro código Application.ScreenUpdating = True End Sub
Comparativa
He modificado el código propuesto por Microsoft aquí pues antes del segundo bucle es necesario mostrar todas las columnas ocultadas tras el primero, o el código no tendría nada que hacer.
Sub Comparativa() Dim stopTime As Single, startTime As Single Dim elapsedtime(2) As Single Application.ScreenUpdating = True For i = 1 To 2 ActiveSheet.Cells.EntireColumn.Hidden = False If i = 2 Then Application.ScreenUpdating = False startTime = Time Worksheets(1).Activate For Each c In ActiveSheet.Columns If c.Column Mod 2 = 0 Then c.Hidden = True End If Next c stopTime = Time elapsedtime(i) = (stopTime - startTime) * 24 * 60 * 60 Next i Application.ScreenUpdating = True MsgBox "Segundos, ScreenUpdating activado: " & elapsedtime(1) & _ Chr(13) & _ "Segundos, ScreenUpdating desactivado: " & elapsedtime(2) End Sub
Ejemplos por separado
Sub Activado() Dim t As Single t = Timer ActiveSheet.Cells.EntireColumn.Hidden = False Application.ScreenUpdating = True Worksheets(1).Activate For Each c In ActiveSheet.Columns If c.Column Mod 2 = 0 Then c.Hidden = True End If Next c Application.ScreenUpdating = True MsgBox Timer - t End Sub
Sub Desactivado() Dim t As Single t = Timer ActiveSheet.Cells.EntireColumn.Hidden = False Application.ScreenUpdating = False Worksheets(1).Activate For Each c In ActiveSheet.Columns If c.Column Mod 2 = 0 Then c.Hidden = True End If Next c Application.ScreenUpdating = True MsgBox Timer - t End Sub
Gracias.
ResponderEliminar