View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Walter Briscoe Walter Briscoe is offline
external usenet poster
 
Posts: 279
Default Optimising loop: was Merging cells and formats

In message of Mon, 6 Jan 2014 13:08:59 in
microsoft.public.excel.worksheet.functions, GS
writes
For clarity, to resist my 'force-of-habit' the entire procedure need
not have events disable as Claus's 3rd post holds true...


[snip]

My thanks to both GS and Claus Busch for their valuable thoughts.
Eventually, I decided to write a VBA procedure to fill a column and
embolden parts of the cells.
At first, I had a loop which did both.
That was unhelpful.
Suppose I concatenate strings "A", "B" and "C" in that order and decide
to embolden "B" with code like
Cells(y, x).Characters(Start:=2, Length:=1).Font.Bold = True.
When "C" is concatenated, it is also emboldened as the appended
characters copy the bold attribute from that "B".

I then found my code slow: about 130 seconds for 1300 rows.
I carefully simplified the code with no noticeable result.
I then googled excel vba optimisation.
The first 2 hits were
<www.cpearson.com/excel/optimize.htm and
<http://www.ozgrid.com/VBA/SpeedingUpVBACode.htm
Chuck Pearson's site is a gold mine and the Ozgrid site looks useful.
I tried bracketing code with
Application.Calculation = xlCalculationManual and
Application.Calculation = xlCalculationAutomatic
and with
Application.ScreenUpdating = False and
Application.ScreenUpdating = True
The result is that my code runs in 1 to 2 seconds.

That is fast enough. I can't publish as the data is confidential.
--
Walter Briscoe

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com