Trebor8484
Board Regular
- Joined
- Oct 27, 2018
- Messages
- 69
- Office Version
- 2013
- Platform
- Windows
Hi all,
Any suggestions how I can amend the below code so that if the condition is true the entire row values are copied to the dictionary to be output to a worksheet at the end of the process.
This will run on over 100,000 rows of data so I was trying to find a way to prevent having to interact with the sheet on each loop iteration and figured that it would be quicker to store in memory then dump it into a sheet at the end of the loop
Any suggestions how I can amend the below code so that if the condition is true the entire row values are copied to the dictionary to be output to a worksheet at the end of the process.
This will run on over 100,000 rows of data so I was trying to find a way to prevent having to interact with the sheet on each loop iteration and figured that it would be quicker to store in memory then dump it into a sheet at the end of the loop
Code:
Sub Test()
Dim c As Range
Dim rng As Range
Dim arrwords As Variant
Dim aword As Variant
Dim dict As Scripting.Dictionary
Dim DictKey As Long
Set dict = New Scripting.Dictionary
Set rng = Sheet1.Range("A2:A" & Sheet1.Cells(Rows.Count, "A").End(xlUp).Row)
arrwords = Array("apple", "pair")
DictKey = 0
For Each c In rng
For Each aword In arrwords
Debug.Print c
If InStr(1, LCase(c.Value), aword, vbBinaryCompare) > 0 Then
DictKey = DictKey + 1
dict.Add DictKey, c.Row
End If
Next aword
Next c
Sheet2.Cells(1, 1).Resize(dict.Count, 15).Value = (dict.Items)
End Sub