use a lookup table within my vba code?

Guitarmageddon

Board Regular
Joined
Dec 22, 2014
Messages
161
So I have a simple vba to reformat a report I use constantly. Its pretty simple, and the report Im reformatting only has one tab.

I want to add onto that code, and basically insert a column which is a vlookup from a store number, to its parent warehouse.This means Im inserting a tab, pasting the lookup data, and just doing a vlook.

However, Im confused on how I can make that vlookup reference table "live" within my vba. Can anyone assist? I hope this makes sense.

So here is what Ive got. This is me inserting the column, and renaming it "parent rdc", followed by me inserting the tab "rdc lookup" that I presumably needed to paste the lookup data for the vba to use. Then, when I want to do the vlookup, the first chunk of commented steps is me pulling the vlookup data from some other sheet. This is basically where I want to make that vlookup data reside within the VBA code. Is that possible?

The second comment is me trying to remember what the dynamic autofill vba was, versus a defined range (since my report length is always different.

VBA Code:
    Columns("N:N").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("N8").Select
    ActiveCell.FormulaR1C1 = "PARENT RDC"
    Range("O11").Select
    Columns("N:N").ColumnWidth = 8
    Sheets.Add After:=ActiveSheet
    Sheets("Sheet1").Select
    Sheets("Sheet1").Name = "RDC LOOKUP"
    
    'Windows("Daily AR Orders 2019.xlsx").Activate
    'Range("A1:C1").Select
    'Range(Selection, Selection.End(xlDown)).Select
    'Selection.Copy
    'Windows("Sales by Style Report.xlsx").Activate
    'Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        'SkipBlanks:=False, Transpose:=False
    
    ActiveSheet.Paste
    Sheets("Page1").Select
    Range("N9").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'RDC LOOKUP'!C1:C3,3,0)"
    'THE NEXT STEPS NEED TO GET CHANGED TO THE AUTOFILL TO END OF DATA
    Range("N9").Select
    Selection.AutoFill Destination:=Range("N9:N279")
    Range("N9:N279").Select

The data that I am trying to make vba use as lookup values is here.
SiteCMDPARENT RDC
01100HHM60001
02100QUM60001
02309QUM60001
04100CPM60001
05100CLM60001
09101SDM70001
10101PNM70001
11100MRM70001
13100TWM70001
14100YUM70001
18100SCM60001
05102CLM60001
05300CLM60001
09100SDM70001
15100KBM70001
16100IWM70001
02212QUM60001
05201CLM60001
05202CLM60001
05207CLM60001
05233CLM60001
05315CLM60001
10252PNM70001
02202QUM60001
02211QUM60001
03100ELM60001
05206CLM60001
08100ALM60001
10113PNM70001
10230PNM70001
10251PNM70001
10321PNM70001
10343PNM70001
13307TWM70001
15101KBM70001
18101SCM60001
05301CLM60001
10320PNM70001
10332PNM70001
15305KBM70001
16001IWM70001
02214QUM60001
05305CLM60001
09700SDM70001
16300IWM70001
02301QUM60001
02305QUM60001
02500QUM60001
09500SDM70001
10001PNM70001
11300MRM70001
05211CLM60001
04200CPM60001
13379TWM70001
15303KBM70001
01200HHM60001
02304QUM60001
04300CPM60001
10314PNM70001
10352PNM70001
10353PNM70001
10362PNM70001
11200MRM70001
15301KBM70001
15400KBM70001
05309CLM60001
09300SDM70001
13305TWM70001
13314TWM70001
05310CLM60001
05311CLM60001
05314CLM60001
05316CLM60001
12100BAM70001
13306TWM70001
14400YUM70001
02205QUM60001
02302QUM60001
02306QUM60001
02307QUM60001
04400CPM60001
05209CLM60001
05302CLM60001
05303CLM60001
05304CLM60001
05306CLM60001
09301SDM70001
10303PNM70001
10304PNM70001
10322PNM70001
10323PNM70001
10324PNM70001
10325PNM70001
10326PNM70001
10331PNM70001
10333PNM70001
10341PNM70001
10342PNM70001
10344PNM70001
10413PNM70001
10451PNM70001
11301MRM70001
13303TWM70001
14301YUM70001
05001CLM60001
05500CLM60001
15001KBM70001
13380TWM70001
01500HHM60001
04500CPM60001
03400ELM60001
10229PNM70001
13101TWM70001
15200KBM70001
16107IWM70001
18301SCM60001
18703SCM60001
18302SCM60001
09103SDM70001
13001TWM70001
12300BAM70001
10118PNM70001
10500PNM70001
05200CLM60001
10364PNM70001
16200IWM70001
12301BAM70001
16301IWM70001
10003PNM70001
02802QUM60001
02801QUM60001
60001EC STOW60001
70001WC STOW70001
16101IWM70001

This is the report that I am attempting to vlook the data into. Column N will reference the existing "SITE" column M, and use the spoiler data I provided above. I have already executed the vlookup below in N as it should end up playing out. This is like a .5 second vlookup to do in normal excel, I just dont get how to make the VBA keep the reference table within itself. Let me know if I can clarify anything!
sbs.PNG
 
Glad you sorted it & thanks for the feedback
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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