Array or Vlookup?

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon!

Sheet1 a b

Os Type
1 aix svr
2 printer svr
3 windows 8.1 ws


Sheet2 a b c

1 D Os
2 N1 Windows 8.1 Enterprise
3 N2 Lexmark Printer
4 N3 Windows 7 Enterprise 64 bit Edition Service Pack 1
5 N4 AIX 5.2


I have two sheets in one wb. (Sheet1 and Sheet2)

Im trying to set the value in column c on sheet2
by scanning columns b's data by each row using the values in columns a's data(sheet1)

I thought I could use a vlookup but think more it might be a array of some type.
Any suggestions?

Thanks

The net effect would be like this


Sheet2 a b c

1 D Os
2 N1 Windows 8.1 Enterprise ws
3 N2 Lexmark Printer svr
4 N3 Windows 7 Enterprise 64 bit Edition Service Pack 1 n/a
5 N4 AIX 5.2 svr
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
here's a pic of the spreasheet

1576786667327.png
 
Upvote 0
If you want the formula:

Book1
ABC
1DOs
2N1Windows 8.1 Enterprisews
3N2Lexmark Printersvr
4N3Windows 7 Enterprise 64 bit Edition Service Pack 1n/a
5N4AIX 5.2svr
Sheet2
Cell Formulas
RangeFormula
C2:C5C2{=IFERROR(INDEX(Sheet1!$B$2:$B$4,MAX(IF(ISNUMBER(SEARCH(Sheet1!$A$2:$A$4,B2)),ROW(Sheet1!$A$2:$A$4)))-1),"n/a")}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


______________________________
Or the macro:

VBA Code:
Sub vlookup_type()
  Dim a, b, c
  Dim i As Long, j As Long
  a = Sheets("Sheet1").Range("A2:B" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row).Value2
  b = Sheets("Sheet2").Range("A2:B" & Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row).Value2
  
  ReDim c(1 To UBound(b, 1), 1 To 1)
  For i = 1 To UBound(b, 1)
    c(i, 1) = "n/a"
    For j = 1 To UBound(a, 1)
      If LCase(b(i, 2)) Like "*" & LCase(a(j, 1)) & "*" Then
        c(i, 1) = a(j, 2)
        Exit For
      End If
    Next
  Next
  Sheets("Sheet2").Range("C2").Resize(UBound(c), 1).Value = c
End Sub
 
Upvote 0
Sweet. Thanks for both solutions as they add to my knowledge of doing it using either an Array or Macro.
I was working on the macro solution myself but your code gives me the understanding of either way.
Where I myself was lost was to use the UBound function.
As always, you guys that provide solutions are Super!

Have a Great day and a better weekend.

Thanks
 
Upvote 0
I'm glad to help you. I appreciate your kind comments.
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,705
Members
449,048
Latest member
81jamesacct

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