#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Slow Macro

I have a fairly simple macro that is runnning slow for some reason. Here is
the code
Application.ScreenUpdating = False
ActiveCell.Range("A1:DS1").Select
Selection.EntireColumn.Hidden = False
ActiveCell.Select
Application.Calculation = xlCalculationManual
For a = 3 To 200
If Range("D3").Offset(0, a).Value = "Hide Column" Then
Range("D3").Offset(0, a).EntireColumn.Hidden = True
Next a
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Any ideas?
--
Thanks for your help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Slow Macro

try this

Option Explicit
Sub HideIfSAS()
Dim lc As Long
Dim i As Long

With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

lc = Cells(3, Columns.Count).End(xlToLeft).Column
Columns(3).Resize(lc - 3).Hidden = False
For i = lc To 3 Step -1
If Cells(3, i) = "Hide Column" Then Columns(i).Hidden = True
Next i

With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"jm913" wrote in message
...
I have a fairly simple macro that is runnning slow for some reason. Here is
the code
Application.ScreenUpdating = False
ActiveCell.Range("A1:DS1").Select
Selection.EntireColumn.Hidden = False
ActiveCell.Select
Application.Calculation = xlCalculationManual
For a = 3 To 200
If Range("D3").Offset(0, a).Value = "Hide Column" Then
Range("D3").Offset(0, a).EntireColumn.Hidden = True
Next a
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Any ideas?
--
Thanks for your help!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Slow Macro

There are a few things you can do to speed your macro up.

1.) Declare your variables. You have a variable a that should be declared
as Dim a As Long.

2.) You can use the With Statement

3.) When looping through objects, in your case cells in a range, I would
recommend using the For Each...Next Loop instead of the For...Next Loop

Try this code. Hope this helps! If so, let me know, click "YES" below.

Sub SlowMacro()

Dim MyRange As Range
Dim rng As Range

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

Set MyRange = Range("A3:DS3")

MyRange.EntireColumn.Hidden = False

For Each rng In MyRange
If rng.Value = "Hide Column" Then
rng.EntireColumn.Hidden = True
End If
Next rng

With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With

End Sub

--
Cheers,
Ryan


"jm913" wrote:

I have a fairly simple macro that is runnning slow for some reason. Here is
the code
Application.ScreenUpdating = False
ActiveCell.Range("A1:DS1").Select
Selection.EntireColumn.Hidden = False
ActiveCell.Select
Application.Calculation = xlCalculationManual
For a = 3 To 200
If Range("D3").Offset(0, a).Value = "Hide Column" Then
Range("D3").Offset(0, a).EntireColumn.Hidden = True
Next a
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Any ideas?
--
Thanks for your help!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Slow Macro

I can barely tell that the macro is even running! You are the Man.

Thanks very much for your help!


"Ryan H" wrote:

There are a few things you can do to speed your macro up.

1.) Declare your variables. You have a variable a that should be declared
as Dim a As Long.

2.) You can use the With Statement

3.) When looping through objects, in your case cells in a range, I would
recommend using the For Each...Next Loop instead of the For...Next Loop

Try this code. Hope this helps! If so, let me know, click "YES" below.

Sub SlowMacro()

Dim MyRange As Range
Dim rng As Range

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

Set MyRange = Range("A3:DS3")

MyRange.EntireColumn.Hidden = False

For Each rng In MyRange
If rng.Value = "Hide Column" Then
rng.EntireColumn.Hidden = True
End If
Next rng

With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With

End Sub

--
Cheers,
Ryan


"jm913" wrote:

I have a fairly simple macro that is runnning slow for some reason. Here is
the code
Application.ScreenUpdating = False
ActiveCell.Range("A1:DS1").Select
Selection.EntireColumn.Hidden = False
ActiveCell.Select
Application.Calculation = xlCalculationManual
For a = 3 To 200
If Range("D3").Offset(0, a).Value = "Hide Column" Then
Range("D3").Offset(0, a).EntireColumn.Hidden = True
Next a
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Any ideas?
--
Thanks for your help!

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
slow macro :)[_2_] Excel Discussion (Misc queries) 1 March 3rd 10 02:41 PM
Slow macro Johan Excel Programming 11 June 22nd 09 06:17 PM
Slow Macro JRK Excel Programming 7 February 6th 09 01:44 AM
slow macro John_A[_2_] Excel Programming 3 March 6th 07 06:36 PM
Slow macro alf bryn Excel Programming 5 August 5th 05 12:27 AM


All times are GMT +1. The time now is 01:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"