Abhijeet R. Joshi
Active Member
Hi all,
After some reaserch I was able to build the below vba code using arrays I did test these on some sample data and then worked well but I made some small changes in the code now its not passing the if function correctly..
Scenario: I am trying to find a value from a range of filtered data in the "data" sheet Col.P against another array in the "Working" Sheet Col.H..and if this passes the if function and finds the value in the other array then correspnding row in Col.X on the data sheet should have a value as "Valid"..
I understand VBA and excel at an average level, but I am completely new to arrays..
Please help...Also if you could suggest some links for array learning in vba that would be great..
After some reaserch I was able to build the below vba code using arrays I did test these on some sample data and then worked well but I made some small changes in the code now its not passing the if function correctly..
Scenario: I am trying to find a value from a range of filtered data in the "data" sheet Col.P against another array in the "Working" Sheet Col.H..and if this passes the if function and finds the value in the other array then correspnding row in Col.X on the data sheet should have a value as "Valid"..
I understand VBA and excel at an average level, but I am completely new to arrays..
Please help...Also if you could suggest some links for array learning in vba that would be great..
Code:
ORIGINAL CODE:
Sub test1()
Dim ary1, ary2, e, temp As String, x
ary1 = Range("A1:A" & Range("D" & Application.Rows.Count).End(xlUp).Row)
ary2 = Range("D2:D3" & Range("D" & Application.Rows.Count).End(xlUp).Row)
For i = 2 To Range("A" & Application.Rows.Count).End(xlUp).Row
'For Each e In ary1
e = Cells(i, 1).Value
x = Application.Match(e, ary2, 0)
If Not IsError(x) Then Cells(i, 2).Value = "Valid"
Next
End Sub
Code:
AMENDED CODE:
Sub test1()
Dim ary1, ary2, e, temp As String, x
Sheets("Working").Select
ary2 = Range("H2:H" & Range("H" & Application.Rows.Count).End(xlUp).Row)
Sheets("Data").Select
ary1 = Range("P2:P" & Range("P" & Application.Rows.Count).End(xlUp).Row)
For i = 2 To Range("P" & Application.Rows.Count).End(xlUp).Row
'For Each e In ary1
e = Cells(i, 16).Value
x = Application.Match(e, ary2, 0)
If Not IsError(x) Then Cells(i, 24).Value = "Valid"
Next
End Sub