[VBA] Application.VLookUp

ExcelNooberino

New Member
Joined
Jan 2, 2019
Messages
40
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
 

Some videos you may like

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

VBE313

Well-known Member
Joined
Mar 22, 2019
Messages
675
Office Version
  1. 365
Platform
  1. Windows
How about..
Rich (BB code):
Desc = WorksheetFunction.VLookup(ACell, shtRList.Range("A:B"), 2, False)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,902
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
 

ExcelNooberino

New Member
Joined
Jan 2, 2019
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
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...
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,902
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

ExcelNooberino

New Member
Joined
Jan 2, 2019
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
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 😓
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,902
Office Version
  1. 365
Platform
  1. Windows
Did you do that in the activecell, or the lookup table?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,483
Messages
5,596,405
Members
414,064
Latest member
Duncthegreat

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
Top