Problem with VLookup Using Application.WorksheetFunction.VLookup

MarkMueller

New Member
Joined
Aug 16, 2018
Messages
23
Office Version
  1. 365
Platform
  1. Windows
I am working on a small Excel Project that builds a UserForm with Selected Data from a Workbook that has 4 sheets of which 2 sheets are important Sheet 2 (Data) and Sheet 3 (Lists).
The (Data) sheet has an area that is populated based on input from the UserForm called: frmTraining. And uses a Criteria Range and Extract Range to highlight the Listbox. Controles at the bottom of the Listbox provide the ability to Input New Trainers, Update Trainer Information, and/or Add New Training.

So I am attempting to lookup the Course Code then automatically populate the Course Name Associated with the Course Code during [Adding New Trainers], I have added a section (Sub) for the Course Name Textbox and within the cmdAdd (Sub), and cmdTraining (Sub). Highlighted the VLookup sections with "-------------" Top and Bottom.

So when the Form loads and I select, from the drop-down [Course Code], the Course Name is not populated. The cmdTraining (Sub) has a different Lookup than the cmdAdd and Reg7 (Sub) I was testing different options.

So I guess I really need to understand what is happening and why? There is obviously a better solution, but I do not know what it is and I have been trying for a week.

Receiving the following error 1004, unable to get VLookup property of the WorksheetFunction class, from the Reg7 (Sub).
 

Attachments

  • Lists_Info_CourseCode_CourseName.png
    Lists_Info_CourseCode_CourseName.png
    43 KB · Views: 8
  • DataPosted.png
    DataPosted.png
    40.2 KB · Views: 7
  • Criteria_Extract.png
    Criteria_Extract.png
    9.2 KB · Views: 9
  • NameRanges.png
    NameRanges.png
    24.1 KB · Views: 10
  • Form.png
    Form.png
    28.7 KB · Views: 9
  • SubReg7.png
    SubReg7.png
    5.5 KB · Views: 9

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Unless I am mistaken, your code is trying to get a value from Column 6 in the range Name LookCourse, which only has 2 columns.

VBA Code:
Reg7.Value = Application.WorksheetFunction.VLookup(Reg6.Value, Sheet3.Range("LookCourse"), 6, 1)

LookCourse = Lists!$H$7:I$388 (where Lista has a code name of Sheet3)

1636369801376.png
 
Upvote 0
Unless I am mistaken, your code is trying to get a value from Column 6 in the range Name LookCourse, which only has 2 columns.

VBA Code:
Reg7.Value = Application.WorksheetFunction.VLookup(Reg6.Value, Sheet3.Range("LookCourse"), 6, 1)

LookCourse = Lists!$H$7:I$388 (where Lista has a code name of Sheet3)

View attachment 50731
Thanks for that, will make that change.
 
Upvote 0
Still receiving the error 1004. Copied as an image.
 

Attachments

  • ErrorExVBA.png
    ErrorExVBA.png
    10.9 KB · Views: 8
Upvote 0
Training_Mng_new.xlsm
ABCDEFGHIJKLMNOPQR
6First NameLast NameScoreStaffIDRoleCourse CodeCourse NameVersionStartedFrequencyDueIDFrequencyStartedDueLast NameRole
7SebastionTherrien10AHS21Shovel OperatorAHS-TDS-1953 FrontRunner Restart34009/16/20203010/16/2020101Shovel Operator
8VincentPike10MMSI4Shovel OperatorAHS-TDS-1931 FrontRunner Foundations32004/10/20203005/10/2020103
9VanessaSimon8AHS05MechanicAHS-TDS-1953 FrontRunner Restart32009/16/202020004/04/2021144
10CarlPerkins10MMSI2ManagerAHS-TDS-1953 FrontRunner Restart32001/28/20193002/27/2019145
11JesseMacDonald7MMSI3ManagerAHS-TDS-1966 FrontRunner Suspend & Release34011/10/20209002/08/2021149
12KevinJanowsky10AHS22Shovel OperatorAHS-TDS-677FR340-STD-LHS-MA-02-entry-emv-collision-risk-ML34012/12/20196002/10/2020150
13VladimirVillarroel9AHS10BlasterAHS-TDS-678FR340-STD-LHS-MA-02-entry-emv-emergency-stop-failure-ML34003/18/20209006/16/2020152
14BreeGorman8AHS18ElectricianAHS-TDS-1964 FrontRunner Obstacles32008/22/202012012/20/2020154
15MarkMueller9AHS99AdministrationAHS-TDS-1955 FrontRunner Escort33010/11/20203011/10/2020156
16TestTester3TST1Shovel OperatorAHS-TDS-1953 FrontRunner Restart32010/11/202012002/08/2021157
17TesticalBalls3TEST1BlasterAHS-TDS-1966 FrontRunner Suspend & Release32010/11/20203011/10/2020158
Data
Cell Formulas
RangeFormula
K17,K12:K15,K8:K10K8=I8+J8
 
Upvote 0
Training_Mng_new.xlsm
NOPQRSTUVWXYZAAABACADAE
4Criteria AreaExtract Area
5
6FrequencyStartedDueLast NameRoleFirst NameLast NameScoreStaffIDRoleCourse CodeCourse NameVersionStartedFrequencyDueID
7Shovel OperatorSebastionTherrien10AHS21Shovel OperatorAHS-TDS-1953 FrontRunner Restart34009/16/20203010/16/2020101
8VincentPike10MMSI4Shovel OperatorAHS-TDS-1931 FrontRunner Foundations32004/10/20203005/10/2020103
9KevinJanowsky10AHS22Shovel OperatorAHS-TDS-677FR340-STD-LHS-MA-02-entry-emv-collision-risk-ML34012/12/20196002/10/2020150
10TestTester3TST1Shovel OperatorAHS-TDS-1953 FrontRunner Restart32010/11/202012002/08/2021157
Data
 
Upvote 0
Training_Mng_new.xlsm
HI
5LookCourse Name Range
6Course CodeCourse Name
7AHS-TDS-193193-1 FrontRunner Foundations
8AHS-TDS-195195-3 FrontRunner Restart
9AHS-TDS-196196-4 FrontRunner Obstacles
10AHS-TDS-197197-5 FrontRunner Escort
11AHS-TDS-198198-6 FrontRunner Suspend & Release
12AHS-TDS-199199-7 FrontRunner Refine Locations
13AHS-TDS-200200-8 FrontRunner Roads & Locations
14AHS-TDS-201201-9 FrontRunner Pass Area
15AHS-TDS-202202-10 FrontRunner Taught Course
16AHS-TDS-203203-11 FrontRunner Dry Run
17AHS-TDS-204204-12 FrontRunner AHT Inspection
18AHS-TDS-205205-13 FrontRunner Loading Unit
19AHS-TDS-206206-14 FrontRunner Dozer Operator
20AHS-TDS-207207-15 FrontRunner Crusher
21AHS-TDS-208208-16 FrontRunner FuelBay Operator
22AHS-TDS-209209-17 FrontRunner Grader
23AHS-TDS-210210-1 FrontRunner Foundations
24AHS-TDS-211211-2 FrontRunner Entry EMV
25AHS-TDS-212212-3 FrontRunner Restart
Lists
 
Upvote 0
So Reg6 represents Course Code on the WorkSheet. Reg7 Represents Course Name. Together they provide the course detail.
 
Upvote 0

Forum statistics

Threads
1,215,411
Messages
6,124,759
Members
449,187
Latest member
hermansoa

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