Macro To Populate Cells

MarkAn

Board Regular
Joined
Sep 28, 2005
Messages
69
Office Version
  1. 2010
Hi

I have a workbook with 2 worksheets - (A & B)
Worksheet B holds a list of teams, I.e. Team 1 in Column A, Team 2 in Column B etc....

On worksheet A, in Cell A1, I have a drop-down with all the relevant teams on worksheet B

What I would like to do, is: If for example, Team 1 is chosen from the drop-down list, the user will then click a button to recover the team members in that team, however, they would need to put in a specific "password" (for that team - they will all have different), as long as the correct password is given, then the list of team members will populate Calls A5:A25 (20 members per team).

this should be pretty simple to do, however, my mind is a total blank as I've not done Macro's in a while

Thanks
MarkAn
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Are the team names listed in the drop down in sheet A also in row 1 of sheet B as headers? You will also need another sheet (which can be hidden) that contains the list of team names in one column and their corresponding passwords in the column to the right of the names.
 
Upvote 0
Hi there
Yes the team names are in Row 1 of sheet B
And I can set up another sheet "C" for the passwords
 
Upvote 0
Create a sheet named "C". In column A of that sheet starting in row 1, place all the team names. In column B place the corresponding team passwords. Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your Sheet A 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 the drop down in A1.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Sheets("B").Range("A" & Rows.Count).End(xlUp).Row
    Dim Team As Range, TName As Range, response As String
    response = InputBox("Please enter the password for Team " & Target & ".", "Enter Password")
    Set Team = Sheets("C").Range("A:A").Find(Target, LookIn:=xlValues, lookat:=xlWhole)
    If Not Team Is Nothing And response = Team.Offset(0, 1) Then
        If Range("A5") <> "" Then
            Range("A5:A" & Range("A" & Rows.Count).End(xlUp).Row).ClearContents
        End If
        Set TName = Sheets("B").Rows(1).Find(Target.Value, LookIn:=xlValues, lookat:=xlWhole)
        Sheets("B").Range(Sheets("B").Cells(2, TName.Column), Sheets("B").Cells(LastRow, TName.Column)).Copy Cells(5, 1)
    Else
        MsgBox ("Invalid password.  Please try again.")
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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