Okay resolved by me..
.....
Sub Macro1()
Dim TINLastRow As Long
Dim TDLastRow As Long
Dim TIN As Worksheet
Dim TD As Worksheet
Dim rng As Long
Set TIN = Worksheets("TIN Master")
Set TD = Worksheets("Tally Data")
TD.Select
If Range("B11") = Empty Or Range("G11") = Empty Or Range("H11") = Empty Then
MsgBox ("Fill Mandatory Feilds!")
Exit Sub
End If
If ActiveSheet.Range("B11").Value = "" Then Exit Sub
Range("$N$11:$R$5000").Select
Selection.ClearContents
Range("$B$11:$B$5010").Select
Selection.Copy
Range("O11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
With TD
rng = Range("O" & Rows.Count).End(xlUp).Row
End With
Range("O11:O" & rng).Select
Selection.RemoveDuplicates Columns:=1, Header:=xlNo
With TIN
TINLastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
With TD
TDLastRow = .Cells(.Rows.Count, "O").End(xlUp).Row
.Range("P11:P" & TDLastRow).Formula = _
"=VLOOKUP(O11,'" & "TIN Master" & "'!$B$10:$C$" & TINLastRow & ",2,0)"
.Range("Q11:Q" & TDLastRow).Formula = _
"=ROUND(SUMIF($B$11:$H$5010,$O11,G$11:G$5010),0)"
.Range("R11:R" & TDLastRow).Formula = _
"=ROUND(SUMIF($B$11:$H$5010,$O11,G$11:G$5010),0)"
End With
End Sub
Bookmarks