VBA problems with finding max values en copying names to a different worksheet.

TimExcel123

New Member
Joined
May 30, 2019
Messages
2
Hi guys,

My name is Tim and I am new to this Forum.
I experience a lot of trouble while designing my first code in Excel VBA. The problem is as following: in column B(worksheet 1), I inserted the names of some students. in column C, I inserted the marks of the corresponding students (see table 1).

In worksheet 2 table 2, I want cells A1:A3 to display the names of the 3 best students. After watching a lot of Youtube-tutorials, I still did not manage tot figure out how to do it. Is there anyone who could help me designing this code in VBA?

Thanks in advance!
-------------------------------------------------------

Table 1 worksheet 1:

StudentMark
Alex
9,5
Sophie7
Nick8
Paul4
Helena9
jan6

<tbody>
</tbody>

table 2 worksheet 2:
Best students
?
?
?

<tbody>
</tbody>
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Using the Large formula you can find the first 3 places.

Code:
Sub finding_max_values()
    Dim i As Long, r As Long
    r = Sheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Row
    For[COLOR=#0000ff] i [/COLOR]= 1 To 3
        Sheets("Sheet2").Range("A" & i + 1).Value = Evaluate _
            ("=INDEX(Sheet1!B1:B" & r & ",SUMPRODUCT((LARGE(Sheet1!C2:C" & r & "+(ROW(C2:C" & r & ")/1000)," &[COLOR=#0000ff] i [/COLOR]& _
            ")=Sheet1!C2:C" & r & "+(ROW(C2:C" & r & ")/1000))*(ROW(C2:C" & r & "))))")
    Next
End Sub

---
Or copying the data from sheet1 to sheet2, sorting and deleting data from 4 down, that way only the first 3 are left.


Code:
Sub Macro6()
    Sheets("Sheet1").Range("B:C").Copy Sheets("Sheet2").Range("A1")
    Sheets("Sheet2").Range("A1").CurrentRegion.Sort key1:=Sheets("Sheet2").Range("B1"), order1:=xlDescending, Header:=xlYes
    Sheets("Sheet2").Range("A5:B" & Rows.Count).ClearContents
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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