[VBA] Application.VLookUp

ExcelNooberino

New Member
Joined
Jan 2, 2019
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
Hello all! I'm trying to create a UserForm where it shows data from the ActiveCell that I've selected in the respective worksheet, but I'm struggling with an error for the VLookUp formula in it. Can somebody tell me what I'm doing wrong in here please? Much thanks in advance! :)

VBA Code:
Private Sub UserForm_Initialize()

Dim Desc As Variant
Dim ACell As Variant
Dim shtRList As Worksheet

Set shtRList = Sheets("REFList")

ACell = ActiveCell.Value
Desc = Application.VLookup(ACell, shtRList.Range("A:B"), 2, False)

Label1.Caption = ACell
Label4.Caption = Desc

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about..
Rich (BB code):
Desc = WorksheetFunction.VLookup(ACell, shtRList.Range("A:B"), 2, False)
 
Upvote 0
Yes, but that does not tell me what the error was & I suspect the error is generated on this line
VBA Code:
Label4.Caption = Desc
 
Upvote 0
Sorry for not providing all the info... The error I'm getting is "Type mismatch" and yes it's on the last line of the sub. I've created a little button just to open the form but it stops me even before that, and I think it's due to the last line because when I verify each line on F8 the rest is all fine...
 
Upvote 0
Ok, how about
VBA Code:
Private Sub UserForm_Initialize()

Dim Desc As Variant
Dim ACell As Variant
Dim shtRList As Worksheet

Set shtRList = Sheets("REFList")

ACell = ActiveCell.Value
Desc = Application.VLookup(ACell, shtRList.Range("A:B"), 2, False)

Label1.Caption = ACell
If IsError(Desc) Then
   Label4.Caption = "N/A"
Else
   Label4.Caption = Desc
End If

End Sub
You are getting the error because it could not find the activecell value in the lookup table.
 
Upvote 0
Ok, how about
VBA Code:
Private Sub UserForm_Initialize()

Dim Desc As Variant
Dim ACell As Variant
Dim shtRList As Worksheet

Set shtRList = Sheets("REFList")

ACell = ActiveCell.Value
Desc = Application.VLookup(ACell, shtRList.Range("A:B"), 2, False)

Label1.Caption = ACell
If IsError(Desc) Then
   Label4.Caption = "N/A"
Else
   Label4.Caption = Desc
End If

End Sub
You are getting the error because it could not find the activecell value in the lookup table.
Ok, that actually works, but I dont get why I get the error! I just tried to insert a " ' " before the number and now it shows the description that I want ?
 
Upvote 0
Did you do that in the activecell, or the lookup table?
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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