Creating VBA Vlookup for 3 columns

arnoudholtzer

New Member
Joined
May 7, 2020
Messages
12
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi ALL,

Can anyone help me out creating a vlookup in macro? Two reasons that i need it to be macro instead of normal formula.
- I need to have empty fields in the exceltable itself and where i got 3 columns that need to be autofilled by vlookup if one of the fields is filled in manually.
- Also i need to get rid of an itterations error as the following formula =if.error(Vlookup(C5,'Sheet2'!A:C;2;False),"") in an example in cell B5 looks up in it's own cell if there's an error and then fills nothing instead of n/a or 0
I don't know if i can add my example excel sheet to this message as i do not see an upload button here... Therefor i just pasted the 2 tables since it's a basic example.

Below is an example of sheet1:
OrdernrNumber xNumber yDescription
1​
3232222​
2233.123.12344Apple
2​
4331311​
2233.133.12345Banana
3​
1123123​
vlookupmacrovlookupmacro
4​
=if.error(Vlookup(C5,'Sheet2'!A:C;2;False),"")1233.113.15555vlookupmacro
5​
vlookupmacrovlookupmacroBerry
6​
vlookupmacrovlookupmacrovlookupmacro
7​
vlookupmacrovlookupmacrovlookupmacro

Below is an example of the datatable to lookup above missing data by vlookup.
Number xNumber yDescription
3232222​
2233.123.12344Apple
4331311​
2233.133.12345Banana
1123123​
1243.133.14222Strawberry
3256666​
1233.113.15555Plum
1423665​
1233.133.14447Berry
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Creating VBA Vlookup for 3 columns
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
would be nice to also get help with my question, instead of help how to use the strange way to attach a file to the post and getting commented on posting it elsewhere as well due to the following reasons:
1. i really want to find a solution for this
2. due to getting questions like why i post this on another forum and inability to post attachment excel example file or unclear how to which brings a delay in someone actually sending a response to my question,
instead of forumrules that should have been made more foolproof / not a problem in the first place.
 
Upvote 0
Hi all,

I've found a script that helps me in my way, but not entirely.
Also created a testfile:
link to test file
Right now i got 2 problems with the vlookup macro:
1. i need to have the macro input the result instead of the formula into the cells.
2. i get an error trying to automate the script to trigger the macro on change in column C, instead of a button.

attached the examplefile with the macro i got so far. (see also below)

Sub Auto_Open()
Dim lrData As Long

lrData = Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp).Row

With Sheets("Sheet1")
.Range("D2:D" & .Range("C" & Rows.Count).End(xlUp).Row).Formula = "=IFERROR(VLOOKUP(C2, 'Sheet2'!C$2:E$" & lrData & ",3, FALSE) , """")"
End With

End Sub

Private Sub Worksheet_Calculate()
'Updateby Extendoffice
Dim Xrg As Range
Set Xrg = Range("C2:C29")
If Not Intersect(Xrg, Range("C2:C29")) Is Nothing Then
Auto_Open
End If
End Sub
 
Upvote 0
A workable sollution was given by "PCI" On this forum:
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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