Dear masters,
i need one code for Lookup entire column, extract maximum value and beside cell value to another cells and need one output column(U).i have one good code. please modify for this correction.
i have tried but not successful. so kindly make a modification. my code is as below:
Sub Generate()
Application.ScreenUpdating = False
LR = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
For i = 4 To LR
If Range("A" & i) <> Range("A" & i - 1) Then
BeamRow = Sheet1.Cells(Rows.Count, "M").End(xlUp).Row + 1
Range("M" & BeamRow) = Range("A" & i)
End If
Next i
LastRow = Sheet1.Cells(Rows.Count, "M").End(xlUp).Row
On Error Resume Next
Range("E4:E" & LR & ",G4:G" & LR).SpecialCells(xlCellTypeConstants, 2).ClearContents
Sheet1.Range("N4:N" & LastRow).Formula = "=MAX(INDEX(($A$4:$A$" & LR & "=$M4)*($E$4:$E$" & LR & "),,))"
Sheet1.Range("O4:O" & LastRow).Formula = "=MAX(INDEX(($A$4:$A$" & LR & "=$M4)*($G$4:$G$" & LR & "),,))"
Sheet1.Range("P4:P" & LastRow).Formula = "=MIN(INDEX(($A$4:$A$" & LR & "=$M4)*($E$4:$E$" & LR & "),,))"
Sheet1.Range("Q4:Q" & LastRow).Formula = "=MIN(INDEX(($A$4:$A$" & LR & "=$M4)*($G$4:$G$" & LR & "),,))"
Sheet1.Range("R4:R" & LastRow).Formula = "=IF($N4<$O4,""MY"",IF($N4>$O4,""MZ"",""Same""))"
Sheet1.Range("T4:T" & LastRow).Formula = "=IF($P4>$Q4,""MY"",IF($P4<$Q4,""MZ"",""Same""))"
Sheet1.Range("W4:W" & LastRow).Formula = "=IF(MAX($N4:$Q4)>MIN($N4:$Q4)*-1,MAX($N4:$Q4),MIN($N4:$Q4))"
Sheet1.Range("V4:V" & LastRow).Formula = "=INDEX($N$3:$Q$3,MATCH($W4,$N4:$Q4,0))"
Sheet1.Range("N4:W" & LastRow).Value = Sheet1.Range("N4:W" & LastRow).Value
Range("E4:E" & LR & ",G4:G" & LR).SpecialCells(xlCellTypeBlanks).Value = "N/A"
Application.ScreenUpdating = True
End Sub
please find sample output file of Excel file.
thanking you,
Best regards.
Bookmarks