Vlookup error in vba

stmarl

New Member
Joined
Jul 13, 2018
Messages
4
Run-Time Error '13':
Type mismatch

Code:
[I]Private Sub CommandButton2_Click()[/I]
[I]Dim CheckTrack As String[/I]
[I]Dim Vlookupticket As String[/I]

[I]CheckTrack = TicketNumber.Value[/I]
[I]Vlookupticket = Application.VLookup(CheckTrack, Sheet2.Range("A:B"), 2, False)[/I]

[I]If IsError(Vlookupticket) Then[/I]
[I]EscalationTitle.Value = "No Ticket found"[/I]
[I]Else[/I]
[I]EscalationTitle.Value = Vlookupticket[/I]

[I]End If[/I]

[I]End Sub[/I]
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Re: Vlookup error in vba Help Needed

Hi, welcome to the forums

You set a lot of variables there, and relying on Vlookup for your intended result isn't necessary

Code:
Private Sub CommandButton2_Click()
Dim findItem As Range


Set findItem = Sheet2.Range("A:A").Find(TicketNumber.Value, Sheet2.Range("A1"))


If Not findItem Is Nothing Then
    EscalationTitle.Value = findItem.Offset(, 1).Value
Else
    EscalationTitle.Value = "No Ticket found"
End If


End Sub

Test this on a copy of your workbook and see if it yields the desired results.
 
Upvote 0
Re: Vlookup error in vba Help Needed

Where are TicketNumber and EscalationTitle set and valued?
If you Dim VlookupTicket as a string then you will get a type mismatch error. Try Dim VlookupTicket as Variant.
 
Upvote 0

Forum statistics

Threads
1,224,803
Messages
6,181,055
Members
453,014
Latest member
Chris258

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