ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Only matach two excel spread sheet (https://www.excelbanter.com/excel-programming/402405-only-matach-two-excel-spread-sheet.html)

Lillian Lian

Only matach two excel spread sheet
 
I have sheet1 and sheet2 both as SSN on columnA like this
sheet1
111-111-111
222-222-222
333-333-333

sheet2
111-111-111
222-222-222
444-444-444

I would like match on sheet3 showing
111-111-111
222-222-222

how do you write the macro for this?

Thanks.

Lillian



joel

Only matach two excel spread sheet
 
Sub matchsheets()

Sh1RowCount = 1
Sh3RowCount = 1
With Sheets("Sheet1")
Do While .Range("A" & Sh1RowCount) < ""
SSN = .Range("A" & Sh1RowCount)
With Sheets("Sheet2")
Set c = .Columns("A:A").Find(what:=SSN, _
LookIn:=xlValues)
If Not c Is Nothing Then
With Sheets("Sheet3")
.Range("A" & Sh3RowCount) = SSN
Sh3RowCount = Sh3RowCount + 1
End With
End If
End With
Sh1RowCount = Sh1RowCount + 1
Loop
End With
End Sub


"Lillian Lian" wrote:

I have sheet1 and sheet2 both as SSN on columnA like this
sheet1
111-111-111
222-222-222
333-333-333

sheet2
111-111-111
222-222-222
444-444-444

I would like match on sheet3 showing
111-111-111
222-222-222

how do you write the macro for this?

Thanks.

Lillian



Lillian Lian

Only matach two excel spread sheet
 
Thanks Joel, it work, your great

"Joel" wrote:

Sub matchsheets()

Sh1RowCount = 1
Sh3RowCount = 1
With Sheets("Sheet1")
Do While .Range("A" & Sh1RowCount) < ""
SSN = .Range("A" & Sh1RowCount)
With Sheets("Sheet2")
Set c = .Columns("A:A").Find(what:=SSN, _
LookIn:=xlValues)
If Not c Is Nothing Then
With Sheets("Sheet3")
.Range("A" & Sh3RowCount) = SSN
Sh3RowCount = Sh3RowCount + 1
End With
End If
End With
Sh1RowCount = Sh1RowCount + 1
Loop
End With
End Sub


"Lillian Lian" wrote:

I have sheet1 and sheet2 both as SSN on columnA like this
sheet1
111-111-111
222-222-222
333-333-333

sheet2
111-111-111
222-222-222
444-444-444

I would like match on sheet3 showing
111-111-111
222-222-222

how do you write the macro for this?

Thanks.

Lillian




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com