josephrozario

New Member
Joined
Mar 31, 2018
Messages
1
<small style="box-sizing: border-box; -webkit-font-smoothing: antialiased; font-size: 11.04px; text-transform: uppercase; display: block; color: rgb(105, 109, 111); font-family: "Helvetica Neue", roboto, Arial, sans-serif; background-color: rgb(238, 242, 244); outline: none !important; -webkit-tap-highlight-color: transparent !important;">
</small>I Have put data validation of subjects in a cell, I need Highest Marks and Student Name to be populated when I select a particular subject.(and if more than one student have the same highest marks, than all the student names) The Subjects are in columns and Student Names are in rows.

Class 10-D Final Exam Report Card
Roll No.Student NameEnglishHindiMathsScienceSocial ScienceTOTALAGGREGATE%
1Ajay Kumar837690918942986
2Mohan Singh897688858041884
3Deepak Bansal817079707737775
4Samir Sharma907893919044288
5Mohit Pandey887185817339880
6Pankaj Mathur787287887740280
7Ashish Pandey949198979047094
8Joseph Rozario939099978846793
SubjectHighest MarksStudent Name
English

<tbody>
</tbody>
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
This macro assumes that your data validation list is in cell B12 and Subject,Highest Marks and Student Name are in B11, C11 and D11 respectively. Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in B12.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("B12")) Is Nothing Then Exit Sub
    Dim bottomA As Long
    bottomA = Range("A" & Rows.Count).End(xlUp).Row
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim maxVal As Range
    Dim sAddr As String
    Range("C12:D" & LastRow).ClearContents
    Set foundSub = Rows(1).Find(Target)
    If Not foundSub Is Nothing Then
        Target.Offset(0, 1) = WorksheetFunction.Max(Range(Cells(2, foundSub.Column), Cells(bottomA, foundSub.Column)))
        Set maxVal = Range(Cells(2, foundSub.Column), Cells(bottomA, foundSub.Column)).Find(Target.Offset(0, 1))
        If Not maxVal Is Nothing Then
            sAddr = maxVal.Address
            Do
                Cells(Rows.Count, "D").End(xlUp).Offset(1, 0) = Cells(maxVal.Row, 2)
                Set maxVal = Range(Cells(2, foundSub.Column), Cells(bottomA, foundSub.Column)).FindNext(maxVal)
            Loop While maxVal.Address <> sAddr
            sAddr = ""
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,479
Messages
6,125,043
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top