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

fi.or.jp.de wrote on 8/2/2011 :
I want to match from sheet2 to Sheet1.

Awaiting for your reply


I believe the code I provided does what you want. So does the in cell
formula I provided in my 2nd reply. So using your example, the code
generates the following:

On Sheet1
A1: IN134566 B1: Yes (in-cell formula also returns "Yes")
A2: IN455544 B1: Yes (in-cell formula also returns "Yes")

If what you want is other than this then post an example of the
expected results.



On Jul 7, 8:40*am, GS wrote:
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 athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


--
Garry

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