Sub getdata()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ws As Worksheet, ws1 As Worksheet
Set ws = Sheets("Sheet2")
Set ws1 = Sheets("Sheet1")
Dim rng As Range, cell As Range, lrow As Long, r1 As Range
Dim lcol As Long, r As Range, lr As Long, str As String
lrow = ws.Cells(Cells.Rows.Count, "a").End(xlUp).Row
Set rng = ws.Range("A2:A" & lrow)
lr = ws1.Cells(Cells.Rows.Count, "a").End(xlUp).Row
Set r = ws1.Range("A2:A" & lr)
For Each cell In rng
If Trim(cell.Value) <> "" Then
str = cell.Value
If Application.WorksheetFunction.CountIf(r, cell.Value) > 0 Then
Set r1 = r.Find(what:=str, after:=ws1.Cells(2, 1), LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
lcol = Cells(r1.Row, Cells.Columns.Count).End(xlToLeft).Column + 1
ws1.Cells(r1.Row, lcol).Value = cell.Offset(0, 1).Value
End If
Else
cell.EntireRow.Interior.ColorIndex = 3
End If
Next cell
ws1.Cells.EntireColumn.AutoFit
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Sub getdata()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ws As Worksheet, ws1 As Worksheet
Set ws = Sheets("Sheet2")
Set ws1 = Sheets("Sheet1")
Dim rng As Range, cell As Range, lrow As Long, r1 As Range
Dim lcol As Long, r As Range, lr As Long, str As String
lrow = ws.Cells(Cells.Rows.Count, "a").End(xlUp).Row
Set rng = ws.Range("A2:A" & lrow)
lr = ws1.Cells(Cells.Rows.Count, "a").End(xlUp).Row
Set r = ws1.Range("A2:A" & lr)
ws1.Select
For Each cell In rng
If Trim(cell.Value) <> "" Then
str = cell.Value
If Application.WorksheetFunction.CountIf(r, cell.Value) > 0 Then
Set r1 = r.Find(what:=str, after:=ws1.Cells(2, 1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
lcol = Cells(r1.Row, Cells.Columns.Count).End(xlToLeft).Column + 1
ws1.Cells(r1.Row, lcol).Value = cell.Offset(0, 1).Value
End If
Else
cell.EntireRow.Interior.ColorIndex = 3
End If
Next cell
ws1.Cells.EntireColumn.AutoFit
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Saurabh...