VBA - Lookup Entire Row from List

Mayanwolfe

New Member
Joined
Jun 5, 2013
Messages
27
Hello,

I am using VBA to create a user entry form where users select certain account numbers from a series of data validation dropdowns (this is already done and functions properly). The workbook also contains a second sheet with all accounts the user could choose from and their attributes. Here is where I need help: when users are done making selections on the first page, they will click a submit button and get back a new workbook with the account numbers they have selected, as well as all the additional matching attribute columns from the lookup sheet. The number of accounts in the user-submitted list may vary, so the range size should be flexible. However, there is always exactly one matching row for each account, so no need to deal with duplicates.

I know how to do this manually using INDEX/MATCH array formulas or by using VLOOKUP in conjunction with the COLUMN function, but I need a VBA solution as this will be part of a larger project to automate the creation of these user forms. So far, I haven't been able to find non-formula solutions to do this. I hope this makes sense. Here's an example.

If a user selects these account numbers on the form page:

10000020020
32000200203
10155563101

The code should lookup these accounts against the full list of accounts and attributes, and create a new workbook with the accounts and all the attribute columns associated with them:

ACCOUNTCREATION_DATECLIENT_NOTYPEACTIVENOTES
1000002002010/24/19500500MANAGEDY
3200020020304/01/202301NONMANAGEDYUnder review.
1015556310101/01/20450054MANAGEDY
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Assuming your data is as shown on sheets 1 and 2 below:

Dante Amor
A
1ACCOUNT
2120
3220
4320
5
Sheet1

#VALUE!


The following macro works with an advanced filter, so the "ACCOUNT" header must be the same on both sheets, as shown in the previous example.

VBA Code:
Sub Macro5()
  With Sheets("Sheet2")
    With .Range("A1", .Range("A" & Rows.Count).End(3))
      .AdvancedFilter 1, Sheets("Sheet1").Range("A1", Sheets("Sheet1").Range("A" & Rows.Count).End(3))
      .EntireRow.Copy
      Workbooks.Add
      ActiveSheet.Paste
    End With
    .ShowAllData
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,669
Messages
6,126,117
Members
449,292
Latest member
Mario BR

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