Trying to create a spreadsheet that combines VLOOKUPs based on inputbox

ExcelDropper

New Member
Joined
Oct 25, 2020
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Hi.

I'm struggling with a macro and was hoping someone could help please.

In the attached workbook I have 5 worksheets. The 'data' worksheet is a list of teams and their respective hard-input values based on a session and category. The 'main' worksheet will do a vlookup for the team inputted in A1, looking to bring back the correct values based on session and category. Before I run my macro (found in thisworkbook), these are the only two worksheets available. After you run the macro, it will create a 'teams' and 'teams list' worksheet. The macro is as follows:

VBA Code:
Sub Teams()
Dim TeamsCount As Long
Dim TeamCode As Variant
Dim i As Long

On Error Resume Next
Sheets("Teams").Delete
Sheets("Teams List").Delete
On Error GoTo 0

Sheets.Add.Name = "Teams"
Sheets.Add.Name = "Teams List"
Sheets("Main").Range("b2:f7").Copy
Sheets("Teams").Range("b2:f7").PasteSpecial xlFormulas

TeamsCount = InputBox("How many teams are you comparing?")
Sheets("Teams List").Activate
For i = 1 To TeamsCount
TeamCode = InputBox("Enter team code: " & i)
Sheets("Teams List").Range("a1").Offset(i - 1, 0).Value = TeamCode
Next i

End Sub


What this does is replicates the data from 'main' to 'teams' without A1. Then, it asks you how many teams you wish to compare and what codes. These codes will be stored in teams list. However, I want to adjust this macro as currently it comes up with #N/As. The reason for this is because its trying to do a VLOOKUP without any value in A1. What I want to happen, as shown by the red sheet, is for each value to do a vlookup to the values in 'teams list'. If you, for the first inputbox, said '2' teams, and for the second inputbox said 'team a' and 'team b', you would get what I have in sheet 'teams list'. Now I just want my 'teams' sheet to replicate the red sheet. Hopefully this makes sense and someone can help me with this please? I've tried myself but as the number of teams are changing every time, the number of vlookups per cell need to change as well, but I'm simply not certain on how to do this.

Thanks for reading.

 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
What about the Main sheet? You have Session 1, 2 and 3 but the Category list can be any number?
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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