Vlookup + Iferror on listObjects

Rita F

New Member
Joined
Jan 27, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I try to write the script with macro for Vlookup between 2 listObjects(dynamic tables) in 2 different sheets (with iferror). I tried the code below that works with regular range, but I want it more dynamical with references to the list-objects:

*********Dim rg As Range
With ActiveSheet
Set rg = .Range("B2") 'Put formulas in cells until end of data in column A
Set rg = Range(rg, .Cells(.Rows.Count, rg.Column).End(xlUp))
rg.Offset(0, 8).Formula = "=IFERROR(VLOOKUP(B2,'quote'!$b:$H,4,FALSE),""0"")"

With ActiveSheet.UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With

Application.CutCopyMode = False
With ActiveSheet.UsedRange
.Value = .Value
End With*********
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Do you want to refer to is as a listobject, or just by name? If the tables already exist then using name would be the easier method (as long as nobody changes the name afterwards).

Table names can be used in vba in the same way as any normal range, for example to use a column named 'Date' in 'Table1' you would use
VBA Code:
With  .Range("Table1[Date]")
In the formula you would write it the same way as if you enter the formula into the sheet manually, for that you could acquire the code from the macro recorder.
 
Upvote 0
Do you want to refer to is as a listobject, or just by name? If the tables already exist then using name would be the easier method (as long as nobody changes the name afterwards).

Table names can be used in vba in the same way as any normal range, for example to use a column named 'Date' in 'Table1' you would use
VBA Code:
With  .Range("Table1[Date]")
In the formula you would write it the same way as if you enter the formula into the sheet manually, for that you could acquire the code from the macro recorder.
I know it, but this case is much complicated than just a name...
 
Upvote 0
Based on your brief question it should be adequate, if it is not then we are going to need more information on what you are trying to do before we will be able to identify a suitable alternative.
 
Upvote 0
Based on your brief question it should be adequate, if it is not then we are going to need more information on what you are trying to do before we will be able to identify a suitable alternative.
It just what i said. i have table X and need to lookup for value from table Y , like on picture bellow
1612103797248.png
 
Upvote 0
I can't see the name of the table in the capture so I've used Table1 in the code. Also, I don't have the (Hindi?) characters used in one of the table names on my laptop in order to retype your exact formula so I've had to substitute that part with [????]

As far as I can see there is no reason for it not to work with table names. From the information that you have provided, this should work just fine once you correct the names as required.

VBA Code:
With Activesheet
    With .Range("Table1[QuantityBP]")
        .Formula= "=IFERROR(VLOOKUP([@LookUpValue],BynetQ[[LookUpValue]:[????]],4,0),0)"
        .Value = .Value
    End With
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,214,858
Messages
6,121,960
Members
449,057
Latest member
FreeCricketId

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