LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Arrays to replace very slow loops ?

Hi I had a post here asking if my loops that run very slowly can be made any
quick.
One suggestion was to replace with an Array.

Now I'm new to VBA and have no idea how to go about Arrays. Below is my code
where I'm finding dulicates based on name fields deleting from that and
adding to another sheet. Here I have 2 text boxes to enter position of Names
Fields and and an option to choose entire FName to be searched instead of
just FName initial.

Now all that I did is replace my r and k range with arrays but I get and
error at this line : If Trim(UCase(Array1(i).Cells(n, strFNameCol))) =
Trim(UCase(Array1(i).Cells(m, strFNameCol))) And _
Trim(UCase(Array1(i).Cells(n, strLNameCol))) = Trim(UCase(Array1(i).Cells(m,
strLNameCol))) . It says runtime error "Runtime error 9 Subscript out of
Range"

My code as below:

Private Sub CmdSubmitNames_Click()
Dim r As Range, _
k As Range
Dim sh As Excel.Worksheet
Dim strFNameCol As String, _
strLNameCol As String
Dim intCounter As Integer, _
intTotDB As Integer, _
totRows As Integer, _
intDupFound As Integer, _
intTotDB2 As Integer, _
i As Integer, _
intTotfile As Integer

Dim Array1(), _
Array2()

totRows = 1026
intCounter = 0

strFNameCol = TxtFNCol.Value
strLNameCol = TxtLNCol.Value
Set r = ActiveWorkbook.ActiveSheet.Range("A:AS")
Set sh = ActiveWorkbook.Worksheets.Add
Set k = sh.Range("A:AS")

Array1 = r.Value
Array2 = k.Value
intTotDB = 1
n = 2

For n = 2 To 1000
If (Array1(i).Cells(n, strFNameCol)) < "" Or _
(Array1(i).Cells(n, strLNameCol)) < "" Then

For m = n + 1 To 1000
If OptEntireFNSearch Then
If Trim(UCase(Array1(i).Cells(n, strFNameCol))) =
Trim(UCase(Array1( i).Cells(m, strFNameCol))) And _
Trim(UCase(Array1(i).Cells(n, strLNameCol))) =
Trim(UCase(Array1(i).Cells(m, strLNameCol))) Then
intDupFound = 1
Array2(i).Rows(intTotDB).Value = Array1(i).Rows(m).Value
intTotDB = intTotDB + 1
Array1(i).Rows(m).Delete
m = m - 1
totRows = totRows - 1
End If
Else
If Trim(UCase(Left(Array1(i).Cells(n, strFNameCol), 1))) =
Trim(UCase(Left(Array1(i).Cells(m, strFNameCol), 1))) And _
Trim(UCase(Array1(i).Cells(n, strLNameCol))) =
Trim(UCase(Array1(i).Cells(m, strLNameCol))) Then
intDupFound = 1
Array2(i).Rows(intTotDB).Value = Array1(i).Rows(m).Value
intTotDB = intTotDB + 1
Array1(i).Rows(m).Delete
m = m - 1
totRows = totRows - 1
End If
End If
Next m


If intDupFound = 1 Then
Array2(i).Rows(intTotDB).Value = Array1(i).Rows(n).Value
intTotDB = intTotDB + 1
Array1(i).Rows(n).Delete
totRows = totRows - 1
n = n - 1
intDupFound = 0
End If

End If
Next n

End_of_Data:
MsgBox "Data Extracted"

End Sub

Thanks In Advance

 
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
Slow Excel Navigation with Up / Down Arrow and slow scrolling deddog Excel Discussion (Misc queries) 0 August 14th 07 09:56 PM
slow replace function hiwan99 Excel Worksheet Functions 3 July 6th 05 11:49 PM
How come replace is so slow? Nathan Excel Discussion (Misc queries) 2 March 23rd 05 03:33 AM
Formula Arrays VERY SLOW in Excel 2002 Patrick Excel Worksheet Functions 2 January 27th 05 12:59 AM
Excel 2000 Slow Loops scain2004 Excel Programming 7 April 4th 04 02:35 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"