Hi
Using your 2 files, put the macro below into a general module in oxno.xls. Have both spreadsheets open and run. Check the output and see how it goes.
Sub aaa()
Dim DataSH As Worksheet
Set DataSH = Workbooks("ox.xls").Sheets("MDI-Shreya4")
Workbooks("oxno.xls").Activate
Sheets("sheet1").Activate
lastdatarow = DataSH.Cells(Rows.Count, 1).End(xlUp).Row
For Each ce In Range("A4:A" & Cells(Rows.Count, 1).End(xlUp).Row)
datarow = Evaluate("=SUMPRODUCT(--('[ox.xls]MDI-Shreya4'!$B$2:$B$" & lastdatarow & "=""" & ce.Value & """),--('[ox.xls]MDI-Shreya4'!$G$2:$G$" & lastdatarow & "=""" & ce.Offset(0, 1).Value & """),(ROW('[ox.xls]MDI-Shreya4'!$C$2:$C$" & lastdatarow & ")))")
If datarow > 0 Then
Cells(ce.Row, "N").Value = DataSH.Cells(datarow, "I").Value
'Cells(ce.Row, "N").Value = datarow
If removenum(Trim(DataSH.Cells(datarow, "L").Value)) = 1 Then
Cells(ce.Row, "O").Value = DataSH.Cells(datarow, "L").Value
ElseIf removenum(Trim(DataSH.Cells(datarow, "M").Value)) = 1 Then
Cells(ce.Row, "O").Value = DataSH.Cells(datarow, "M").Value
End If
If removenum(Trim(DataSH.Cells(datarow, "J").Value)) = 1 Then
Cells(ce.Row, "T").Value = DataSH.Cells(datarow, "J").Value
ElseIf removenum(Trim(DataSH.Cells(datarow, "M").Value)) = 1 Then
Cells(ce.Row, "T").Value = DataSH.Cells(datarow, "M").Value
End If
End If
Next ce
End Sub
Function removenum(xx) As Integer
Set regex = CreateObject("Vbscript.regexp")
With regex
.Pattern = "[0-9]"
.Global = True
removenum = Len(.Replace(xx, ""))
End With
Set regex = Nothing
End Function
rylo
Bookmarks