Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Trying to improve the performance of my code

Hi All

with following code i'm splitting up text into rows.
The textpassages aren't longer than ColWidth.
'-------------------------------------------------------
Sub Tool_Hyphenation(TextSplit As String, EndRange As Range, ColWidth As
Double, Collength as Byte)

Dim tmpstr, ApprovedStr, StrScore As String
Dim Arrstr, ArrTmpStr, ArrScore As Variant
Dim Fontsize_ As Single
Dim Linenr, LenArrStr, ScoreCount As Integer

Fontsize_ = 7.5
Arrstr = Split(TextSplit)

Columns("IV").Clear
Columns("IV").Font.Size = Fontsize_
Columns("IV").Font.Name = "ITCFranklinGothic LT Book"
Linenr = 1
tmpstr = ""

For i = 0 To UBound(Arrstr)

tmpstr = Trim(tmpstr & " " & Arrstr(i))
If Len(tmpstr) ColLength Then
ActiveSheet.Range("IV" & Linenr) = tmpstr
Columns("IV:IV").AutoFit
If Columns("IV:IV").ColumnWidth <= ColWidth Then
ApprovedStr = tmpstr
Else
ActiveSheet.Range("IV" & Linenr) = ApprovedStr
Linenr = Linenr + 1
tmpstr = Arrstr(i)
End If
End If
Next i

If Range("IV" & Linenr).FormulaR1C1 < tmpstr Then
Range("IV" & Linenr).FormulaR1C1 = tmpstr
End If

Range("IV1:IV" & Linenr).copy Range(EndRange)
Columns("IV:IV").Clear

End Sub
'-------------------------------------------------------

The problem now is, that this code, like it is now, is really slow.
Does anyone has an idea how the performance can be improved?
I improved it a little with the use of Collength, which controls the
length of tmpstring.

I appreciate every comment.

Thanks in advance

Carlo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Trying to improve the performance of my code

try adding these 2 lines at the beginning of your code:

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

and add these before the end sub:

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

--


Gary


"Carlo" wrote in message
...
Hi All

with following code i'm splitting up text into rows.
The textpassages aren't longer than ColWidth.
'-------------------------------------------------------
Sub Tool_Hyphenation(TextSplit As String, EndRange As Range, ColWidth As
Double, Collength as Byte)

Dim tmpstr, ApprovedStr, StrScore As String
Dim Arrstr, ArrTmpStr, ArrScore As Variant
Dim Fontsize_ As Single
Dim Linenr, LenArrStr, ScoreCount As Integer

Fontsize_ = 7.5
Arrstr = Split(TextSplit)

Columns("IV").Clear
Columns("IV").Font.Size = Fontsize_
Columns("IV").Font.Name = "ITCFranklinGothic LT Book"
Linenr = 1
tmpstr = ""

For i = 0 To UBound(Arrstr)

tmpstr = Trim(tmpstr & " " & Arrstr(i))
If Len(tmpstr) ColLength Then
ActiveSheet.Range("IV" & Linenr) = tmpstr
Columns("IV:IV").AutoFit
If Columns("IV:IV").ColumnWidth <= ColWidth Then
ApprovedStr = tmpstr
Else
ActiveSheet.Range("IV" & Linenr) = ApprovedStr
Linenr = Linenr + 1
tmpstr = Arrstr(i)
End If
End If
Next i

If Range("IV" & Linenr).FormulaR1C1 < tmpstr Then
Range("IV" & Linenr).FormulaR1C1 = tmpstr
End If

Range("IV1:IV" & Linenr).copy Range(EndRange)
Columns("IV:IV").Clear

End Sub
'-------------------------------------------------------

The problem now is, that this code, like it is now, is really slow.
Does anyone has an idea how the performance can be improved?
I improved it a little with the use of Collength, which controls the
length of tmpstring.

I appreciate every comment.

Thanks in advance

Carlo



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Trying to improve the performance of my code

Hi Gary

thank you for your input!

instead of 40 seconds it ran for 36 seconds. Which is still long!
But it is an improvement!

I hope someone can give me a hint with which i am able to
go down to a duration of maximum 20 seconds or so!
Would really appreciate it.

Thanks again

Carlo

"Gary Keramidas" wrote:

try adding these 2 lines at the beginning of your code:

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

and add these before the end sub:

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

--


Gary


"Carlo" wrote in message
...
Hi All

with following code i'm splitting up text into rows.
The textpassages aren't longer than ColWidth.
'-------------------------------------------------------
Sub Tool_Hyphenation(TextSplit As String, EndRange As Range, ColWidth As
Double, Collength as Byte)

Dim tmpstr, ApprovedStr, StrScore As String
Dim Arrstr, ArrTmpStr, ArrScore As Variant
Dim Fontsize_ As Single
Dim Linenr, LenArrStr, ScoreCount As Integer

Fontsize_ = 7.5
Arrstr = Split(TextSplit)

Columns("IV").Clear
Columns("IV").Font.Size = Fontsize_
Columns("IV").Font.Name = "ITCFranklinGothic LT Book"
Linenr = 1
tmpstr = ""

For i = 0 To UBound(Arrstr)

tmpstr = Trim(tmpstr & " " & Arrstr(i))
If Len(tmpstr) ColLength Then
ActiveSheet.Range("IV" & Linenr) = tmpstr
Columns("IV:IV").AutoFit
If Columns("IV:IV").ColumnWidth <= ColWidth Then
ApprovedStr = tmpstr
Else
ActiveSheet.Range("IV" & Linenr) = ApprovedStr
Linenr = Linenr + 1
tmpstr = Arrstr(i)
End If
End If
Next i

If Range("IV" & Linenr).FormulaR1C1 < tmpstr Then
Range("IV" & Linenr).FormulaR1C1 = tmpstr
End If

Range("IV1:IV" & Linenr).copy Range(EndRange)
Columns("IV:IV").Clear

End Sub
'-------------------------------------------------------

The problem now is, that this code, like it is now, is really slow.
Does anyone has an idea how the performance can be improved?
I improved it a little with the use of Collength, which controls the
length of tmpstring.

I appreciate every comment.

Thanks in advance

Carlo




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
Improve the performance of Excel 2007. Heera Excel Worksheet Functions 1 October 23rd 08 03:14 AM
Help Optimizing a Sheet to improve performance Vulcan Excel Worksheet Functions 2 June 14th 08 02:56 AM
How do I improve the 2007 Excel performance. Pete Excel Discussion (Misc queries) 1 April 26th 08 06:43 PM
PageBreak problem. How to improve performance? [email protected] Excel Programming 2 September 23rd 05 01:55 AM
Advanced Filters - improve performance ? IrelandA Excel Programming 1 August 26th 03 05:41 PM


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

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"