Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Auto Populate a range of data

0

I have a list of Players in column A. I would like to be able to select a name and have a set of statistics populate from another worksheet in an area I designate. The set of data is about 5 columns and 5 rows. I would like to be able to slect any name from Column A and have this data change per name I select. This sounds easy but I can not figure it out.  VBA, formula? Any help would be appreciated. 

Edit: I have 25 players in column A. The data I have is per player. So if I select "Joe" in cell A# I would like Joe's stats to appear in a designated area. His stats are 5 columns of 5 rows. Then I would like to select "Frank" in Cell A# and have his stats appear. The data would appear in the same spot but only showing one player at a time. 

Answer
Discuss

Discussion

Hello Avsrick and welcome to the Forum.

I'm not clear on the question (please edit it to clarify rather than replying here)- does each player have 5x5 cells to describe their performance or is it 5 players each with 5 parameters? If it's the former, how many players?

It helps us to help you if you attach your work-to-date as an Excel file (to do that, edit your original question and use the Add files... button below the text box).
John_Ru (rep: 6142) Apr 23, '21 at 10:24 am
Add to Discussion

Answers

0

Rick

Thanks for the expanded question and comment that you prefer not to use a drop down list.

In my revised answer/ attached file, I've added a VBA macro (see code below).

It uses the worksheet event SelectionChange to detect when another cell is picked from whatever data is in column A of sheet1. Pick a name from column A and the stats in K2:P7 will change (but will be blank for my addition Phil since there's no player data on Sheet2).

I've added comments to explain what's going on:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim LastRowA As Integer

' Check that selected cell is in the player column
LastRowA = Range("A" & Rows.Count).End(xlUp).Row 'find last row of column A containing data
If Intersect(Target, Range("A2:A" & LastRowA)) Is Nothing Then Exit Sub

' Copy player name to results section and clear stats
Range("K2").Value = Target.Value
Range("K3:P7").Value = ""

'Find target name in stats page
Dim Names As Range
With Sheet2
    Set Names = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
    'Cycle through used cells to find player name
    For Each Cll In Names
        If Cll.Value = Target.Value Then
        'If found, copy stats to Sheet1
            Sheet1.Range("L3:P7").Value = Cll.Offset(0, 1).Resize(5, 5).Value
        End If
    Next Cll
End With

End Sub
Note that it relies on each player's data in sheet 2 being in the same format- see Joe's stats (shaded pale yellow, noting that I moved his name into A2 to match how Frank's stats were presented).

You can add your other players to Sheet2 in the same format and the macro will continue to work.

The stats just change on Sheet 1 as you pick players but, if necessary, the colour of the K2:P7 could be toggled to show a change has been made. I haven't done that yet.

I don't know anything about baseball but hope this makes sense and helps.

Discuss

Discussion

Thank you John. Thats close to what I had in mind. I would prefer not to use a drop down list if possible. I am attaching an example of what i am envisioning. Where I have Joe selected on sheet1 I would like his last 5 games to appear. If drop down and select Frank, his last 5 replace Joe's on Sheet1 K2 cell. Now if I can figure out how to attach my example...
avsrick Apr 23, '21 at 2:25 pm
Rick
See my revised Answer. Have a good weekend too!
John_Ru (rep: 6142) Apr 24, '21 at 1:10 am
Forgot to say, you can rename the sheets (by right click/Rename while in tab on worksheet view) without affecting the operation. Wasn't sure how you planned to label the week stats but you can put your labels (game dates?) in Sheet 1 cells J3:K7.
John_Ru (rep: 6142) Apr 24, '21 at 4:09 am
Hi Rick
Did that work?
John_Ru (rep: 6142) Apr 26, '21 at 11:14 am
I guess not! 
John_Ru (rep: 6142) Apr 27, '21 at 6:04 pm
Add to Discussion
0

Hello Avsrick,

I was looking at posts which didn't indicate "Answer Selected" and came upon yours. With baseball season just around the corner I decided to find a possible answer to your question. It intrigued me as something I could solve and possibly learn from (which I did). In my attached file I have added sheets to your original file – "Player Stats" (sheet3 - modification of your sheet1) and "Team Stats" (sheet4 - modification of your sheet2). Both sheets have added notes to help explain how everything works.

On the "Team Stats" sheet select a player from the drop down list ("B2") and then click on the "Get Player's Stats" button to display that player's stats in the table to the right. Click on the "Update Players List" button to ensure the drop down list is current.

On the "Team Stats" sheet, if you need to update a player's stats, select the player from the drop own list ("J1") and then click on the "Update Player's Stats" button. If you want to add a new player click on the "Add New Player" button.

Feel free to edit/adapt macros as needed to suit your specific needs.

For the 'buttons' I used shapes – just like Don prefers – as they can be easily modified for more visual appeal.

If you like my suggestion please mark it as "Selected Answer".

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login