How can I evaluate multiple text values to confirm if they are all the same or if they are different and return a set text value?

PinPinPoola

New Member
Joined
Aug 17, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a workbook with 2 tabs. Cabinets and Equipment.

Cabinets has a single row per cabinet
Equipment has multiple rows per cabinet

For each Cabinet Name in the Cabinets Tab, I need to evaluate all rows of the Cabinet Name in Equipment Tab and return into the Contains Equipment Owned By of Cabinets Tab if the the owner is either "Network Ops", "IT Ops" or "Shared" - where shared cabinets contain equipment owner by both Network Ops AND IT Ops.

I have tried an XLOOKUP, but this only returns the first Equipment Owner encountered for each Cabinet Name in the Equipment tab.

Cabinets Tab

Cabinet IDCabinet NameContains Equipment Owned ByCabinet Size
1AA01Network Ops48U 800x1200 HPE Adv Rack
2AA02Shared48U 800x1200 HPE Adv Rack
3AA03IT Ops48U 800x1200 HPE Adv Rack


Equipment Tab

Equipment IDCabinet NameEquipment OwnerEquipment
1AA01Network OpsCisco Switch
2AA01Network OpsCisco Switch
3AA01Network OpsCisco Router
4AA01Network OpsCisco Firewall
5AA02Network OpsCisco Switch
6AA02Network OpsCisco Switch
7AA02IT OpsHPE ProLiant Server
8AA02IT OpsHPE ProLiant Server
9AA02IT OpsHPE ProLiant Server
10AA02IT OpsHPE SAN Storage
11AA02Network OpsHPE SAN Switch
12AA02Network OpsHPE SAN Switch
13AA03IT OpsHPE ProLiant Server
14AA03IT OpsHPE ProLiant Server

Any help, advice or pointers will be greatly appreciated.

Thx
Pin
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Make sure that your sheets are named "Equipment" and "Cabinets". Try this macro. Do the following: Hold down the ALT key and press the F11 key. This will open the Visual Basic Editor. In the menu at the top, click "Insert" and then click "Module". Copy/paste the macro into the empty window that opens up. Press the F5 key to run the macro. Close the code module window to return to your sheet. There are other quicker ways to run the macro such as assigning it to a button that you would click on your sheet or assigning it to a short cut key.
VBA Code:
Sub owner()
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet, cabName As Range, fRow As Long
    Set srcWS = Sheets("Equipment")
    Set desWS = Sheets("Cabinets")
    LastRow = desWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each cabName In desWS.Range("B2:B" & LastRow)
        With srcWS
            .Range("A1").CurrentRegion.AutoFilter 2, cabName
            fRow = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Row
            If WorksheetFunction.CountIf(.Range("C2", .Range("C" & .Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible), "Network Ops") > 0 _
                    And WorksheetFunction.CountIf(.Range("C2", .Range("C" & .Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible), "IT Ops") > 0 Then
                cabName.Offset(, 1) = "Shared"
            Else
                cabName.Offset(, 1) = .Range("C" & fRow)
            End If
        End With
    Next cabName
    srcWS.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
@mumps Thank you so much for your help. I have left the office for the day, so I will try this when I get home.
Pin
 
Upvote 0
You could also do this by formula.

PinPinPoola.xlsm
ABCD
1Equipment IDCabinet NameEquipment OwnerEquipment
21AA01Network OpsCisco Switch
32AA01Network OpsCisco Switch
43AA01Network OpsCisco Router
54AA01Network OpsCisco Firewall
65AA02Network OpsCisco Switch
76AA02Network OpsCisco Switch
87AA02IT OpsHPE ProLiant Server
98AA02IT OpsHPE ProLiant Server
109AA02IT OpsHPE ProLiant Server
1110AA02IT OpsHPE SAN Storage
1211AA02Network OpsHPE SAN Switch
1312AA02Network OpsHPE SAN Switch
1413AA03IT OpsHPE ProLiant Server
1514AA03IT OpsHPE ProLiant Server
Equipment


PinPinPoola.xlsm
ABCD
1Cabinet IDCabinet NameContains Equipment Owned ByCabinet Size
21AA01Network Ops48U 800x1200 HPE Adv Rack
32AA02Shared48U 800x1200 HPE Adv Rack
43AA03IT Ops48U 800x1200 HPE Adv Rack
Cabinets
Cell Formulas
RangeFormula
C2:C4C2=LET(ownr,UNIQUE(FILTER(Equipment!C$2:C$15,Equipment!B$2:B$15=Cabinets!B2)),IF(ROWS(ownr)=1,ownr,"Shared"))
 
Upvote 0
You're welcome.

I'm not sure which method you have chosen but if you have used the formula method then note that I made a slight error with that formula. Whilst it works as shown, it is a very bad idea to use the worksheet name of the sheet the formula is in as that can lead to inconspicuous error in some circumstances. So since the formula is on sheet 'Cabinets' it should be corrected like this
=LET(ownr,UNIQUE(FILTER(Equipment!C$2:C$15,Equipment!B$2:B$15=Cabinets!B2)),IF(ROWS(ownr)=1,ownr,"Shared"))

PinPinPoola.xlsm
ABCD
1Cabinet IDCabinet NameContains Equipment Owned ByCabinet Size
21AA01Network Ops48U 800x1200 HPE Adv Rack
32AA02Shared48U 800x1200 HPE Adv Rack
43AA03IT Ops48U 800x1200 HPE Adv Rack
Cabinets
Cell Formulas
RangeFormula
C2:C4C2=LET(ownr,UNIQUE(FILTER(Equipment!C$2:C$15,Equipment!B$2:B$15=B2)),IF(ROWS(ownr)=1,ownr,"Shared"))
 
Upvote 0
Solution
@Peter_SSs You have gone over and above; a thousand thank yous!

I decided to use your formula method as it does not require the user to enable the VBA content each time the workbook is opened.

I have just made the formula correction you mentioned.

Pin
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,037
Members
449,062
Latest member
mike575

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