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
How is that combo being populated?
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
The concept is to use the UserForm to represent what is occurring with the Training Workbook via the Data and Lists Worksheets. The Form utilizes controls at the bottom to provide the ability to Add New Trainers (Command Button) of which is Coded, Update Training (Command Button) does changes entered within the Text Box's above. So initially I use the Role drop-down to select a role and then click Lookup Staff (Command Button). Data from Sheet2 (Criteria selects) then Extract lists the data within the Forms Listbox. Double-clicking a selection from items within the Listbox then populates the textboxes below the Listbox.
 
Upvote 0
That does not answer my question.
 
Upvote 0
So, all Comboboxe's are loaded from the Lists sheet as name ranges and then the name range is added to the RowSouce in the items properties.
 
Upvote 0
Also attached the Lists Sheet via an Image in my initial posting. e.g. it is the first image. Hope that helps, if not let me know what I need to provide!
 
Upvote 0
In that case, as long as you are selecting an item from the list & not free-typing, I can see no reason why you would get the error.
 
Upvote 0
' Update Reg7 (Course Name in Control Area), based on Lookup from entry into Reg6 Control (DropDown)
Private Sub Reg7_Change()
Reg7.Value = Application.WorksheetFunction.VLookup(Reg6.Value, Sheet3.Range("LookCourse"), 2, 1)
MsgBox Reg7
MsgBox Reg6
End Sub

(Reg7 Represent the Course Name), (Reg6 Represents the Course Code)
The above Sub is creating the error: Run-time error 91: Object variable or With block variable not set.
 
Upvote 0
Missed where you had the cod, why is it in the Reg7 change event, rather than the reg6 change event?
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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