Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Match using VBA

Hi All,

I have a excel file with two sheets.

Sheet1 has data like this
IN134566
IN455544

Sheet2 has data like this
IN00000134566
IN00000455544

So, I need to match sheet1 data is available or not in sheet2, if its
available then in the
next cell i need value "YES"

FYI - Sheet2 - there may be 4 zero's or 6 zero's
Sheet2 has duplicate values,

Thanks in advance.




  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Match using VBA

If you prefer an in-cell formula...

In Sheet1!B1: (or any column you choose)
=IF(COUNTIF(Sheet2!$A:$A,$A1)0,"Yes","")

...and copy down as required.

--
Garry

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Match using VBA

I want to match from sheet2 to Sheet1.

Awaiting for your reply



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


  #5   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup Formula: Return 1st match, then 2nd match, then 3rd match Scott Excel Discussion (Misc queries) 4 December 11th 09 05:50 AM
index(match) Wind Uplift Calculations (match four conditions) JMeier Excel Worksheet Functions 8 August 1st 08 01:45 AM
MATCH Multiple Criteria & Return Previous / Penultimate Match Sam via OfficeKB.com Excel Worksheet Functions 27 October 6th 07 01:39 AM
Lookup? Match? pulling rows from one spreadsheet to match a text f cjax Excel Worksheet Functions 3 July 21st 06 02:51 PM
searching a list box for a filename match...and highlighting the match suee[_4_] Excel Programming 1 April 13th 04 02:56 AM


All times are GMT +1. The time now is 02:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"