VBA for VLOOKUP

nik0101

New Member
Joined
Apr 11, 2018
Messages
1
Hi,

I'm new to VBA and wanted some help drafting out a code that would help me automate the following process:

1. Create different sheets based off of names on a master sheet (eg: below)
2. List corresponding product names to a particular name in the respective sheets (for instance: Adam would have products A and E, and Billy would have B,D,G,L,M as per the table below)
3. List corresponding costs for each product.

So sheet Adam should have:
<style><!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";}@page {margin:.75in .7in .75in .7in; mso-header-margin:.3in; mso-footer-margin:.3in;}tr {mso-height-source:auto;}col {mso-width-source:auto;}br {mso-data-placement:same-cell;}td {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:black; font-size:12.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Calibri, sans-serif; mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;}--></style>
ProductCost
A1
E5

<tbody>
</tbody>

<style><!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";}@page {margin:.75in .7in .75in .7in; mso-header-margin:.3in; mso-footer-margin:.3in;}tr {mso-height-source:auto;}col {mso-width-source:auto;}br {mso-data-placement:same-cell;}td {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:black; font-size:12.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Calibri, sans-serif; mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;}--></style>

Sample Table:
NameProductCost
AdamA1
BillyB2
TonyC3
BillyD4
AdamE5
TonyF6
BillyG7
JillH8
FrankI9
JillJ10
FrankK11
BillyL12
BillyM13

<tbody>
</tbody>

Any guidance/help would be really helpful.

Thanks.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this. Assumes your table of names is on Sheet1 with the "Name" header in A1.
Code:
Set Sht1 = Sheets("Sheet1")
Set R = Sht1.Range("A1").CurrentRegion
Application.ScreenUpdating = False
With Sht1
    .Columns("E").ClearContents
    R.Columns(1).AdvancedFilter Action:=xlFilterCopy, copytorange:=Sht1.Range("E1"), unique:=True
    For Each Nam In .Range("E2:E" & Cells(Rows.Count, "E").End(xlUp).Row)
        On Error Resume Next
        Application.DisplayAlerts = False
        Sheets(Nam.Value).Delete
        Application.DisplayAlerts = True
        On Error GoTo 0
        Sheets.Add after:=Sheets(Sheets.Count)
        ActiveSheet.Name = Nam.Value
        With R
            .AutoFilter field:=1, Criteria1:=Nam.Value
            On Error Resume Next
            .Columns(2).Resize(, 2).SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets(Nam.Value).Range("A1")
            On Error GoTo 0
        End With
        R.AutoFilter
    Next Nam
    .Columns("E").ClearContents
End With
Sht1.Select
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,024
Messages
6,128,333
Members
449,443
Latest member
Chrissy_M

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