A how to, just can't find the answer anywhere! Please help me!!

U

UKDeluded

Okat, a spreadsheet with two tabs. Let's say tab one has | UID | DOB | NOSE
SIZE | (for example), tab 2 has |UID| No of Ears | Nose hair |

I would like to take duplicates where UID is the same out of tabs 1 and 2
and put into a new tab with | UID | DOB | No of ears | Nose hair | so third
tab has all people from tab one and two which exist in both and a cross
section of information from tab 1 and 2.

Have I confused anyone?!?

Thank you all because you're bound to be much cleverer than I is.
 
B

Bob Phillips

You should be abole to adapt this

Public Sub ProcessData()
Const COL_TAB1_UID As String = "A"
Const COL_TAB1_DOB As String = "B"
Const COL_TAB2_UID As String = "F"
Const COL_TAB2_EARS As String = "I"
Const COL_RESULTS_UID As String = "A"
Const COL_RESULTS_DOB As String = "B"
Const COL_RESULTS_EARS As String = "C"
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
Dim cell As Range
Dim sh As Worksheet
Dim newSheet As Worksheet

On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Results").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Set newSheet = Worksheets.Add
newSheet.Name = "Results"
Set sh = Worksheets("Tab 2")
With Worksheets("Tab 1")

LastRow = .Cells(.Rows.Count, COL_TAB1_UID).End(xlUp).Row
newSheet.Cells(1, COL_RESULTS_UID).Value = "UID"
newSheet.Cells(1, COL_RESULTS_DOB).Value = "DoB"
newSheet.Cells(1, COL_RESULTS_EARS).Value = "No. of Ears"
NextRow = 1
For i = 2 To LastRow

Set cell = Nothing
Set cell = sh.Cells(1, COL_TAB2_UID).EntireColumn.Find(.Cells(i,
COL_TAB1_UID).Value)
If Not cell Is Nothing Then

NextRow = NextRow + 1
newSheet.Cells(NextRow, COL_RESULTS_UID).Value = .Cells(i,
COL_TAB1_UID).Value
newSheet.Cells(NextRow, COL_RESULTS_DOB).Value = .Cells(i,
COL_TAB1_DOB).Value
newSheet.Cells(NextRow, COL_RESULTS_EARS).Value =
sh.Cells(cell.Row, COL_TAB2_EARS).Value
End If
Next i

End With

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top