View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default even the codes in microsoft's help section don't work

Hi Kyle,

You have Option Explicit at the top of the VBA editor screen. This demands
that all variables be declared. It is the preferred professional way to go.
Try the following with the variables declared.

Sub test()

Dim i As Integer
Dim StartTime As Date
Dim StopTime As Date
Dim c As Range
Dim elapsedTime(2)

Application.ScreenUpdating = True

For i = 1 To 2
If i = 2 Then Application.ScreenUpdating = False
StartTime = Time
Worksheets("Sheet1").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 "Elapsed time, screen updating on: " & elapsedTime(1) & _
" sec." & Chr(13) & _
"Elapsed time, screen updating off: " & elapsedTime(2) & _
" sec."

End Sub

--
Regards,

OssieMac


"kyle" wrote:

i found this code by pressing screenupdating in the help section of vba. it
doesn't work. it says i is undefined. so i write dim i as integer. then it
says starttime is undefined.

Dim elapsedTime(2)
Application.screenupdating = True

For i = 1 To 2
If i = 2 Then Application.screenupdating = False
startTime = Time
Worksheets("Sheet1").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 "Elapsed time, screen updating on: " & elapsedTime(1) & _
" sec." & Chr(13) & _
"Elapsed time, screen updating off: " & elapsedTime(2) & _
" sec."