Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default even the codes in microsoft's help section don't work

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."

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default even the codes in microsoft's help section don't work

I pasted this code into a new module and it seemed to work just
fine for me. I don't know what the hell it did, but it seemed to
work. The sheet flickered and the columns changed really quickly...
then it showed a dialog box that stated elapsed time and
screen updating numbers.

The only reason I can think why Excel is telling you that your variables
are undefined is probably because you have a line of code at the
top of your module that says "Option Explicit"??? just my first
guess


"kyle" wrote in message
...
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."


  #3   Report Post  
Posted to microsoft.public.excel.programming
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."

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
How do I: If Pie Section Label = X, Make Pie Section Color = Y MikeZz Excel Programming 2 September 3rd 08 08:35 PM
Microsoft's drop down box Sulley Excel Programming 3 March 12th 07 01:28 AM
Excel 2007. How to Get Microsoft's Attention Chaplain Doug Excel Programming 2 February 16th 07 05:54 PM


All times are GMT +1. The time now is 09:56 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"