PDA

View Full Version : Return All Matching Rows On Button Press



jo15765
11-16-2016, 05:08 PM
On my Sheet1 there is a drop down list that shows all the schools that attended an event. I want to add a button, and on the button press event pull all information from the school that is displayed from the list.

For example, if School1 is selected pull all rows from sheet2 where School1 exists in column A (including headers, so row 1) back to Sheet1 starting in A8.

An example workbook is found here http://s000.tinyupload.com/?file_id=98113972907022391661 (http://s000.tinyupload.com/index.php?file_id=98113972907022391661)

So if school1 is selected from the list, what vba code would return the follwoing data to A8 and below


School
Student
Score
Time
Place


School1
Student1
50
2
9


School1
Student2
40
3
3


School1
Student3
10
5
1

p45cal
11-17-2016, 05:15 AM
No need for a button press, just change the dropdown selection in B2 in attached.
Code in sheet1 code-module is:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then Sheets("Sheet2").Range("A1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("B1:B2"), CopyToRange:=Range("A8:E8"), Unique:=False
End Sub