Copy over cells from different sheet2 if name match

evenyougreg

New Member
Joined
Oct 1, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
In this example file, sheet1 is called List and sheet 2 is called VMs.

If there is a "Hostname" match between the 2 sheets, I would like to copy the "OS" cell and the "Env" cell over from "VMs" to the "List" sheet. If no match is found then it would be cool if something like "not found" was to fill the empty cells.

Thank you!!

example.xlsx
ABCDEF
1HostnameVM/PhysicalPower StateOSLocationEnv
2l-centtest01VMonWest
3l-ubu01VMonEast
4l-ubu02VMonWest
5l-webapp01VMonEast
6l-webapp02VMonEast
7m-iisapp01PhysicalonWest
8m-iisapp02PhysicalonEast
9m-poc01VMonEast
10m-poc02VMonWest
11m-sqldb01PhysicalonWest
12m-dsc01VMonEast
13m-dsc02VMonWest
List


example.xlsx
ABC
1HostnameOSEnv
2l-centtest01CentOS 7prod
3l-ubu01Ubuntu 20.04prod
4l-ubu02Ubuntu 20.04test
5l-webapp01RHEL 7prod
6l-webapp02RHEL 7prod
7m-iisapp01Windows-2012ServerR2prod
8m-iisapp02Windows-2012ServerR2prod
9m-poc01Windows-2019Servertest
10m-poc02Windows-2019Servertest
11m-sqldb01Windows-2016Serverprod
12m-sqldbtestWindows-2016Servertest
VMs
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Excel Formula:
=IFNA(INDEX(VMs!B2:B12,MATCH(H2,VMs!A2:A12,0)),"Not found")
 
Upvote 0
Here is another way using xlookup.

Book2
ABCDEF
1HostnameVM/PhysicalPower StateOSLocationEnv
2l-centtest01VMonCentOS 7Westprod
3l-ubu01VMonUbuntu 20.04Eastprod
4l-ubu02VMonUbuntu 20.04Westtest
5l-webapp01VMonRHEL 7Eastprod
6l-webapp02VMonRHEL 7Eastprod
7m-iisapp01PhysicalonWindows-2012ServerR2Westprod
8m-iisapp02PhysicalonWindows-2012ServerR2Eastprod
9m-poc01VMonWindows-2019ServerEasttest
10m-poc02VMonWindows-2019ServerWesttest
11m-sqldb01PhysicalonWindows-2016ServerWestprod
12m-dsc01VMonNot FoundEastNot Found
13m-dsc02VMonNot FoundWestNot Found
List
Cell Formulas
RangeFormula
D2:D13D2=XLOOKUP(A2:A13,VMs!A2:A12,VMs!B2:B12,"Not Found")
F2:F13F2=XLOOKUP(A2:A13,VMs!A2:A12,VMs!C2:C12,"Not Found")
Dynamic array formulas.
 
Upvote 0
Here is another way using xlookup.

Book2
ABCDEF
1HostnameVM/PhysicalPower StateOSLocationEnv
2l-centtest01VMonCentOS 7Westprod
3l-ubu01VMonUbuntu 20.04Eastprod
4l-ubu02VMonUbuntu 20.04Westtest
5l-webapp01VMonRHEL 7Eastprod
6l-webapp02VMonRHEL 7Eastprod
7m-iisapp01PhysicalonWindows-2012ServerR2Westprod
8m-iisapp02PhysicalonWindows-2012ServerR2Eastprod
9m-poc01VMonWindows-2019ServerEasttest
10m-poc02VMonWindows-2019ServerWesttest
11m-sqldb01PhysicalonWindows-2016ServerWestprod
12m-dsc01VMonNot FoundEastNot Found
13m-dsc02VMonNot FoundWestNot Found
List
Cell Formulas
RangeFormula
D2:D13D2=XLOOKUP(A2:A13,VMs!A2:A12,VMs!B2:B12,"Not Found")
F2:F13F2=XLOOKUP(A2:A13,VMs!A2:A12,VMs!C2:C12,"Not Found")
Dynamic array formulas.

That worked:) Sometimes the amount of rows changes week to week, is there a way to remove the hard coded row amount, and to run until it finds the end of the list?
 
Upvote 0
Just change the two formulas to:
=XLOOKUP(A2:A13,VMs!A:A,VMs!B:B,"Not Found")
=XLOOKUP(A2:A13,VMs!A:A,VMs!C:C,"Not Found")
 
Upvote 0
Or this to make it fully dynamic:
=XLOOKUP(INDIRECT("A2:A" & COUNTA(A:A)),VMs!A:A,VMs!B:B,"Not Found")
=XLOOKUP(INDIRECT("A2:A" & COUNTA(A:A)),VMs!A:A,VMs!C:C,"Not Found")
 
Upvote 0
Solution
Or this to make it fully dynamic:
=XLOOKUP(INDIRECT("A2:A" & COUNTA(A:A)),VMs!A:A,VMs!B:B,"Not Found")
=XLOOKUP(INDIRECT("A2:A" & COUNTA(A:A)),VMs!A:A,VMs!C:C,"Not Found")
Bingo, I can kinda see how it works so I can reuse it. Thanks so much!
 
Upvote 0
@eastrand I posted a more VBA focused thread involving your answer, if you are able to chime in I would appreciate it, if not no worries and thank you again.

 
Upvote 0

Forum statistics

Threads
1,224,944
Messages
6,181,928
Members
453,073
Latest member
bfrobin

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