Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Programming exercise, array

I wish to seek advice on speeding up these processes.

I read a 180,000 lines of text file in an array in Excel 2000.
From this 180,000 element array, I used instr method to extract 150,000
elements into a new array. It takes about 2.3 seconds (see code A).

With this 150,000 element array, I performed search for keywords 6 times,
again using instr method. It takes 16 seconds (see code B).

When either the size of the array increases or I need to search for more
keywords, the processing time increases to an annoying level.

Is there any other way of achieving faster results please?

Regards
Victor

Code A
j = 0
For x = 1 To i 'i = 180,000
If InStr(1, arrLarge(x), c, vbTextCompare) 0 Then
arrCat(j + 1) = arrLarge(x)
j = j + 1
End If
Next x

Code B
For y = 2 To x 'x = 7 thus 6 keywords
k = 0
For z = 1 To j 'j = 150,000
If InStr(1, arrCat(z), Cells(c.Row, y), vbTextCompare) 0
Then k = k + 1
Next z
If k < 0 Then
wsr.Cells(c.Row * 3 - 11, y) = k
End If
If k = 0 Then
wsr.Cells(c.Row * 3 - 11, y) = "NOT found"
End If
Next y
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Programming exercise, array


In Code A, why not start with J =1
Change arrCat(J + 1) to arrCat(j)
Change j = j + 1 to j = j + 2
That would eliminate 180, 000 addition operations.

In Code B, I don't know how c.Row is arrived at, so won't comment.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Victor"
wrote in message
I wish to seek advice on speeding up these processes.

I read a 180,000 lines of text file in an array in Excel 2000.
From this 180,000 element array, I used instr method to extract 150,000
elements into a new array. It takes about 2.3 seconds (see code A).

With this 150,000 element array, I performed search for keywords 6 times,
again using instr method. It takes 16 seconds (see code B).

When either the size of the array increases or I need to search for more
keywords, the processing time increases to an annoying level.

Is there any other way of achieving faster results please?

Regards
Victor

Code A
j = 0
For x = 1 To i 'i = 180,000
If InStr(1, arrLarge(x), c, vbTextCompare) 0 Then
arrCat(j + 1) = arrLarge(x)
j = j + 1
End If
Next x

Code B
For y = 2 To x 'x = 7 thus 6 keywords
k = 0
For z = 1 To j 'j = 150,000
If InStr(1, arrCat(z), Cells(c.Row, y), vbTextCompare) 0
Then k = k + 1
Next z
If k < 0 Then
wsr.Cells(c.Row * 3 - 11, y) = k
End If
If k = 0 Then
wsr.Cells(c.Row * 3 - 11, y) = "NOT found"
End If
Next y
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Programming exercise, array

Thank you for your suggestion, Jim.
I tried, but do not notice any significant difference please

Regards
Victor

"Jim Cone" wrote:


In Code A, why not start with J =1
Change arrCat(J + 1) to arrCat(j)
Change j = j + 1 to j = j + 2
That would eliminate 180, 000 addition operations.

In Code B, I don't know how c.Row is arrived at, so won't comment.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Victor"
wrote in message
I wish to seek advice on speeding up these processes.

I read a 180,000 lines of text file in an array in Excel 2000.
From this 180,000 element array, I used instr method to extract 150,000
elements into a new array. It takes about 2.3 seconds (see code A).

With this 150,000 element array, I performed search for keywords 6 times,
again using instr method. It takes 16 seconds (see code B).

When either the size of the array increases or I need to search for more
keywords, the processing time increases to an annoying level.

Is there any other way of achieving faster results please?

Regards
Victor

Code A
j = 0
For x = 1 To i 'i = 180,000
If InStr(1, arrLarge(x), c, vbTextCompare) 0 Then
arrCat(j + 1) = arrLarge(x)
j = j + 1
End If
Next x

Code B
For y = 2 To x 'x = 7 thus 6 keywords
k = 0
For z = 1 To j 'j = 150,000
If InStr(1, arrCat(z), Cells(c.Row, y), vbTextCompare) 0
Then k = k + 1
Next z
If k < 0 Then
wsr.Cells(c.Row * 3 - 11, y) = k
End If
If k = 0 Then
wsr.Cells(c.Row * 3 - 11, y) = "NOT found"
End If
Next y

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
Lottery exercise Gary''s Student Excel Worksheet Functions 1 December 5th 05 07:20 PM
A 13 period exercise Steved Excel Worksheet Functions 1 August 9th 05 09:29 AM
Array Type programming Xavier Susai Excel Programming 1 April 12th 04 04:34 PM
Programming Array Formulas in VBA - Can they be intermediate results in RAM? Bill Hertzing Excel Programming 4 February 17th 04 07:04 PM
Array formulas into VB programming Angelo Battistoni Excel Programming 3 August 28th 03 05:34 PM


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