View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Looping thru Sheets without activating

Hi Myles,

Try:

Public Sub Tester03()
Dim SH As Worksheet
Dim c As Range
Dim CalcMode As Long

On Error GoTo XIT

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

For Each SH In Worksheets
For Each c In SH.Range("a:a")
If Not IsEmpty(c) Then
'<Do something
End If
Next c
Next SH

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============


---
Regards,
Norman


"Myles" wrote in
message ...

I have a code that loops through 56 Worksheets and on each sheet loops
through the used cells in Column A. Does anyone have a way to execute
the two-phase looping without activating the Worksheets? Following the
line of least resistance, and at the expense of speed, I have:

For each sh in WorkSheets
sh.activate
For each c in Range("a:a")
If Not IsEmpty(c) Then

<Do something

End if
Next
Next


I reckon that the code could be vastly speeded up if it didn't have to
select each sheet.

TIA.

Myles.


--
Myles
------------------------------------------------------------------------
Myles's Profile:
http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=496613