I have to following code to loop a large amount of data in an excel spreadsheet. However it takes a very long time to loop through the data( around 8 minutes) and produce a result.
In the code I pick one entry from spreadsheet one to loop through spreadsheet two entries and find any entries to contain a reference to it.
The entry from Spreadsheet one used for the loop is: 'AZ-567887'
A sample entry in spreadsheet two that is looped through is: 'Heeny Eamon, AZ-345342, LK TANK' and another one is: 'Thomas-TZ679001-escape of water (GAB)'
So, I transfered to data from the excel spreadsheet into ms access in the hope I can run quicker. However, I have never used VBA in access before. Could anyone help me and tell me the changes I need to make to the code above to allow it to run in access?
In the code I pick one entry from spreadsheet one to loop through spreadsheet two entries and find any entries to contain a reference to it.
The entry from Spreadsheet one used for the loop is: 'AZ-567887'
A sample entry in spreadsheet two that is looped through is: 'Heeny Eamon, AZ-345342, LK TANK' and another one is: 'Thomas-TZ679001-escape of water (GAB)'
Code:
option explicit
Sub do_check2()
Dim i As Integer, j As Integer, k As Integer
Dim first_string As String
Dim str_length As Integer
Dim column_array() As Integer
Dim vnt_temp As Variant
Dim array_index As Integer
Const column_numbers = "2,3,8,9,14,15,20,21,26,27"
' Create an array of the column numbers you are interested in
vnt_temp = Split(column_numbers, ",")
ReDim column_array(0 To UBound(vnt_temp))
For array_index = 0 To UBound(vnt_temp)
column_array(array_index) = vnt_temp(array_index)
Next
' Now do your loop
For i = 2 To 30002
For j = 2 To 2
' At this point we can save the items that are only variable with respect to j rather than processing them each time
first_string = remove_characters(UCase(Sheets(1).Cells(j, 3).Value))
str_length = Len(Sheets(1).Cells(j, 3).Value)
For k = 1 To Len(Sheets(3).Cells(i, 3).Value)
' Now cycle through all your columns
For array_index = 0 To UBound(column_array)
If first_string = remove_characters(UCase(Mid(Sheets(3).Cells(i, column_array(array_index)).Value, k, str_length))) Then
Sheets(1).Cells(j, 3).Value = "x"
Sheets(3).Cells(i, column_array(array_index) + 3).Value = "y"
End If
Next array_index
Next k
Next j
Next i
End Sub
Function remove_characters(value_in)
value_in = Replace(value_in, " ", "")
value_in = Replace(value_in, "-", "")
value_in = Replace(value_in, ".", "")
value_in = Replace(value_in, "/", "")
remove_characters = value_in
End Function
So, I transfered to data from the excel spreadsheet into ms access in the hope I can run quicker. However, I have never used VBA in access before. Could anyone help me and tell me the changes I need to make to the code above to allow it to run in access?