Thread: Match using VBA
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Match using VBA

Where is the next cell in relation to the data cell in sheet1?

If ToRight:

Sheet1:
A1: IN134566
A2: IN455544

Sheet2:
A1: IN00000134566
A2: IN00000455544

Sub MatchValues()
Dim lLastRow As Long, j As Long, k As Long
Dim vData1 As Variant, vData2 As Variant

lLastRow = Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.Count ,
1).End(xlUp).Row
vData1 = Sheets("Sheet1").Range("$A$1:$A$" & lLastRow)
lLastRow = Sheets("Sheet2").Cells(Sheets("Sheet2").Rows.Count ,
1).End(xlUp).Row
vData2 = Sheets("Sheet2").Range("$A$1:$A$" & lLastRow)

For j = LBound(vData1) To UBound(vData1)
For k = LBound(vData2) To UBound(vData2)
If InStr(1, vData2(k, 1), Mid$(vData1(j, 1), 3)) 0 Then
Sheets("Sheet1").Cells(j, 2) = "Yes": Exit For
End If
Next 'k
Next 'j
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc