Selected Answer
In the attached demonstration workbook I have made a few preparations.
- The table on the Data tab is called DataTable. This name recurs in the formulas. The reason for creating a table is to have all ranges dynamic by default, meaning you can add or delete rows without the need to change formulas.
Note that all cells in the table are formatted as Text as should be all cells in the Pick sheet that reference them.
- On the Pick tab I created a validation dropdown in B3. It refers to the column UserName of the DataTable table. Add a name to the table and it appears in the dropdown without further ado because all column ranges are dynamic.
Observe that the UserName column is the first column in the table so that it can be used with the VLOOKUP function.
- Picks!C3 contains this formula
=IFERROR(VLOOKUP($B$3,DataTable,2,FALSE),"")
It retrieves the reference number matching the user name. This is probably different from what you intended because the user can't enter or select the reference number which would require a little more effort. You will only need that if you want to allow several identical user names in the list.
- Finally, there are two formulas in B9 abd C9 of the Pick sheet as follows.
[B9] =INDEX(DataTable[#Headers],,ROW()-5)
[C9] = IFERROR(IF(VLOOKUP($B$3,DataTable,3,FALSE)=$C$5,VLOOKUP($B$3,DataTable,ROW()-5,FALSE),"No match"),"Invalid User")
Copy both formulas down as required.
Both formulas refer to the active row number in order to reference a table column. The ROW() function is used to create a counter here. =ROW() returns the number of the row in which the formula resides, in my example 9 because it resides in row 9. ROW()-5 therefore returns 4 which is the 4th column in the DataTable. Now, as the formula is copied down ROW() successively returns 10, 11, 12 etc. In context it specifies columns 5, 6, 7 etc of the DataTable.
Now, you can select a user name in the dropdown, see the matching reference number in the adjacent cell but no data. Enter a password in C5. If it matches the password in the DataTable the data will be displayed.
I suggest that you hide the Data tab by the following method.
- Open the VBA Editor
- Make sure that the Properties pane is displayed (left bottom).
- Click on the Data sheet's name in the Project Explorer pane on the left, above the Properties pane. The sheet's properties will be displayed.
- Scroll down to the Visible property and change the setting to xlSheetVeryHidden.
The sheet can't be made visible again from the user interface. The only way to make it visible is to reset the Visible property to xlSheetVisible in the VBA Editor window. To make this more difficult you can protect the VBA Project with a password. Such passwords can be broken easily by any determined hacker but they can't be broken accidentally.
To set a password for the VBA project, click on the VBA Project in the Project Explorer and select VBA Project Properties from the dropdown that opens.