View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default [Q] For, Next - How to Speed Up

Oops! I left something out. Geez.., I hate when that happens!!!
Couple of things to consider...

VB read/write from/to ranges is inherently slow.

Using an If...Then construct slows it down even more because VB has to
evaluate every iteration. Mind you, there's only 3 so this should be a hardly
negligable hit on performance.

Whenever you write to a range it works faster if you set...

Dim bEventsEnabled As Boolean, lCalcMode As Long
With Application
bEventsEnabled = .EnableEvents: lCalcMode = .Calculation


.EnabeEvents = False: .Calculation = xlCalculationManual

.ScreenUpdating = False
End With 'Application

'//do stuff

With Application
.EnableEvents = bEventsEnabled: .Calculation = lCalcMode
.ScreenUpdating = True
End With 'Application

As John suggests, it would be better to 'dump' the ranges into a 2D array and
work the values in memory, then 'dump' the array back into the sheet.

VBA will NEVER be as fast or efficient as Excel's build-in functions. That
said, the following cell formula will update immediatelt when/as the ref cell
change...

Select B1:B3
Type: =IF($A1,"OK","")

..so if any cell in A1:A3 contains "TRUE" then its respective neighbor in
B1:B3 will display "OK", or return an empty string.


--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc