Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default Slow Macro "CheckSum()"

CheckSum sums a column of Hex numbers. It gets really slow with larger
column sizes.
16k takes 5 seconds,
32k takes 16 seconds,
64k takes over 60 seconds.
Any tips to spead this up. Excel 97.

Sub CheckSum()
Dim r As Range
Dim HexByte As Variant
Dim NewHex As Variant
Dim ChkSum As Variant
Dim FileNameOnly As Variant
ChkSum = 0
RowStart = 1
RowSize = 65536
RowStop = RowStart + RowSize - 1
For Each r In Range("C" & RowStart & ":C" & RowStop).Rows
ChkSum = ChkSum + Val("&h" & UCase(r.Text))
Next 'Next r
Range("D1").Value = Right(Hex(ChkSum), 4)
Beep
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Slow Macro "CheckSum()"

Try getting the data into a variant arry and then processing that
something like this

Sub CheckSum()
Dim r As Range
Dim HexByte As Variant
Dim NewHex As Variant
Dim ChkSum As Variant
Dim FileNameOnly As Variant

dim vData as variant
dim j as long

ChkSum = 0
RowStart = 1
RowSize = 65536
RowStop = RowStart + RowSize - 1
vData=Range("C" & RowStart & ":C" & RowStop).Value2

for j=lbound(vdata) to ubound(vdata)
ChkSum = ChkSum + Val("&h" & UCase(vData(j,1)))
Next j

Range("D1").Value = Right(Hex(ChkSum), 4)
Beep
End Sub


Charles
___________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Fan924" wrote in message
...
CheckSum sums a column of Hex numbers. It gets really slow with larger
column sizes.
16k takes 5 seconds,
32k takes 16 seconds,
64k takes over 60 seconds.
Any tips to spead this up. Excel 97.

Sub CheckSum()
Dim r As Range
Dim HexByte As Variant
Dim NewHex As Variant
Dim ChkSum As Variant
Dim FileNameOnly As Variant
ChkSum = 0
RowStart = 1
RowSize = 65536
RowStop = RowStart + RowSize - 1
For Each r In Range("C" & RowStart & ":C" & RowStop).Rows
ChkSum = ChkSum + Val("&h" & UCase(r.Text))
Next 'Next r
Range("D1").Value = Right(Hex(ChkSum), 4)
Beep
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default Slow Macro "CheckSum()"

Wow Charles! Thanks. It now finishes in under a second. Exactly what I
was looking for.

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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Read ".dll" files, the Macro "work flow" and the actual values of the variables when Macro is running [email protected] Excel Programming 5 May 16th 07 08:18 PM
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" Dennis Excel Discussion (Misc queries) 0 July 17th 06 02:38 PM
Will using a "personal macro workbook" slow down my other VBA code Stacymm Excel Programming 1 September 24th 05 03:35 PM
Sending macro based e-mail with built-in "Heading" and "Text" Prabha Excel Programming 3 January 17th 05 02:11 PM


All times are GMT +1. The time now is 02:35 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"