Building relationships vs Xlookup

Reba

New Member
Joined
May 25, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
So I have a working code that uses xlookups to pull values from one table to another. That I can do and my code works fine. For reference here's the working code:

VBA Code:
Option Explicit
Dim RT As ListObject, PTO As ListObject, Tot As ListObject, C3 As ListObject
Dim WS As Worksheet

Sub Review_Time()
    Sheets("Genesys").Activate
    Set WS = ActiveSheet
    Set Tot = WS.ListObjects(1)
With Tot
    .ListColumns("CMS Name").DataBodyRange.Formula2 = "=Xlookup([@[Agent Name]],CCC_Employees[GenesysID],CCC_Employees[CMS Name])"
    .ListColumns("Employee ID").DataBodyRange.Formula2 = "=xlookup([@[Agent Name]],CCC_Employees[GenesysID],CCC_Employees[Employee ID])"
    With .ListColumns.Add
    .Name = "Department"
    .DataBodyRange.Formula2 = "=xlookup([@[agent name]],CCC_Employees[GenesysID],CCC[Department])"
End With
End Sub

However, I was wondering if there is a better way to write this using relationships.
I would like to set CCC_Employees[Genesys ID] as the primary key with the foreign key being [agent name] so that I could then do something like:

VBA Code:
.listcolumns("CMS Name").databodyrange = CCC_Employees[CMS Name]
.listcolumns ("Employee ID").databodyrange = CCC_Employees[Employee ID]
.listcolumns("Deparment").databodyrange = CCC_Employees[Department]

Not sure if this is possible, or worth the effort of doing but my full code is full of xlookups that I feel could be replaced with relationships if only I knew how. I'm looking for the most efficient method as I'm working in VERY large datasets so any advice would be greatly appreciated! Thanks in advance
 

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.

Forum statistics

Threads
1,215,327
Messages
6,124,289
Members
449,149
Latest member
mwdbActuary

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