I am comparing 2 arrays, and based off the comparison, placing values from an array into a range using the active cell. I am not receiving errors, but two things are happening.
1. Excel (not my machine) locks up when I run the code - How can I improve my code so this does not happen
2. I believe the information is mismatching within my arrays. element 1 of myArray corresponds with element 1 of myArray2, the same for element 2, etc. How do I define bounds telling the computer to start with element 1 of each array?
Here is my code:
1. Excel (not my machine) locks up when I run the code - How can I improve my code so this does not happen
2. I believe the information is mismatching within my arrays. element 1 of myArray corresponds with element 1 of myArray2, the same for element 2, etc. How do I define bounds telling the computer to start with element 1 of each array?
Here is my code:
Code:
Sub Example()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Dim myArray() As Variant
Dim myArray2() As Variant
Dim i As Long
Dim rng As Range
Dim element As Variant
Dim element2 As Variant
myArray = Range("B3:B128").Value
myArray2 = Range("C3:C128").Value
If ActiveSheet.Name = "Example Sheet 1" Then
Worksheets("Example Sheet 2").Activate
If ActiveSheet.Name = "Example Sheet 3" Then
Worksheets("Example Sheet 4").Activate
Else
End If
End If
Set rng = ActiveSheet.Range("M2:M5000")
For Each element In myArray
For Each element2 In myArray2
For Each cell In rng
If cell.Value = element Then
cell.Activate
cell.Offset(columnoffset:=2).Activate
ActiveCell.Value = element2
Else
End If
Next cell
Next element2
Next element
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: