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
Missed where you had the cod, why is it in the Reg7 change event, rather than the reg6 change event?
I guess, I thought that the change was occurring in Reg7 and not Reg6. Reg6 is the initial check to see if Reg7 has similar detail. in another Sub, I attempted to do the same thing but highlighted the specific criteria via using Right and Left text commands. Code below:

'add value to the next row in the database
nextrow = Reg1.Value ' FName
nextrow.Offset(0, 1) = Reg2.Value ' LName
nextrow.Offset(0, 2) = Reg3.Value ' Grade
nextrow.Offset(0, 3) = Reg4.Value ' StaffID
nextrow.Offset(0, 4) = Reg5.Value ' Role
nextrow.Offset(0, 5) = Reg6.Value ' Course Code
' This section Below may not be working - added Msgbox.
' Set ws = ActiveSheet
If (Right(Reg6, 3)) = (Left(Reg7, 3)) Then
Reg7.Value = Application.VLookup(Reg7.Value, Sheet3.Range("H:I"), 8, 0)
' ++++++ Message Box for Reg 7 ++++++++
MsgBox (" +++ Variable ++++ = " & Reg7)
End If
nextrow.Offset(0, 6) = Reg7.Value ' Course Name
nextrow.Offset(0, 7) = Reg8.Value ' Version
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I think I have become confused as to what is occurring, fairly new at Excel VBA, the code above is from the cmdADD Sub and relates to the Add New Trainers (Command Button). Still do not know the correct syntax for the Sub Reg7. Sorry for not being very helpful, I think.
 
Upvote 0
Try putting the code in the reg6 click event like
VBA Code:
Private Sub Reg6_Click()
Reg7.Value = Application.VLookup(Reg6.Value, Sheet3.Range("LookCourse"), 2, 1)
MsgBox Reg7
MsgBox Reg6
End Sub
 
Upvote 0
Solution
Try putting the code in the reg6 click event like
VBA Code:
Private Sub Reg6_Click()
Reg7.Value = Application.VLookup(Reg6.Value, Sheet3.Range("LookCourse"), 2, 1)
MsgBox Reg7
MsgBox Reg6
End Sub
That is just about it. Thanks a lot.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

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