Finding Text in a field

Barchetta99

New Member
Joined
Apr 8, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

Thanks for taking the time to look at my issue.

I have a field,
e.g. this hat is red

Named Range List - contains words in priority order and
1 red
2 hat
3 this
4 test
5 animal
6 word

Named Range Comment - is used by vlookup to pull out the comments i want to make.
1 red - Ruby Red
2 hat - hat on head
3 this - this old house
4
5
6 word - a word by no deed



I am looking for about 40 words.
I'm using this formula
VLOOKUP(INDEX(List,SUMPRODUCT(ISNUMBER(SEARCH(List,I47))*ROW($1:$41))),Comment,2,FALSE)

Answer Returned = value 6 - A Word by no deed.

In using this formula I can find the words and if my list had unique words only it would work.

Instead what is happening is where multiple words are found in a field the sum products add the values together and come up with a new value which is incorrect based on the logic of a priority ordered list.

I'd like the list to stop looking as soon as it finds a word, I'm thinking i probably need to use a vba case statement for each word to get it stop rather than progress?
I am looking at circa 32,000 rows to then create a pivot on the most frequent words based on this hierarchy. I then need to repeat it monthly.

Any thoughts gratefully received.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi and welcome to MrExcel.

It is an array formula, find the first word from top to bottom of the named range "List".
In the first example: "this hat is red" the first word in named range "List" is red.

If you want another classification or the sheet is very slow with array formulas, then the other option is a macro.

Dante Amor
ABCDEFG
1e.g.AnswerLISTComment
2this hat is redRuby RedredredRuby Red
3this sweter is blackthis old househathathat on head
4this hat is whitehat on headthisthisthis old house
5This is a test formulathis old housetestworda word by no deed
6some textno matchesanimal
7word
Hoja8
Cell Formulas
RangeFormula
B2:B6B2=IFERROR(VLOOKUP(INDEX(List,SMALL(IF(ISNUMBER(SEARCH(List,A2)),ROW(List)),1)),Comment,2,0), "no matches")
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Considering the data as I put in my example, try the following macro.

VBA Code:
Sub answer()
  Dim a As Variant, b As Variant, c As Variant, d As Variant
  Dim dic As Object, i As Long, j As Long
  
  a = Range("A2", Range("A" & Rows.Count).End(3)).Value2
  b = Range("List")
  c = Range("Comment")
  ReDim d(1 To UBound(a), 1 To 1)
  
  Set dic = CreateObject("Scripting.dictionary")
  For i = 1 To UBound(c)
    dic(c(i, 1)) = c(i, 2)
  Next
  
  For i = 1 To UBound(a)
    For j = 1 To UBound(b)
      If InStr(1, a(i, 1), b(j, 1), vbTextCompare) > 0 Then
        d(i, 1) = dic(b(j, 1))
        Exit For
      End If
    Next
  Next
  Range("B2").Resize(UBound(d)).Value = d
End Sub
 
Upvote 0
Thanks for your swift response, I hadn't thought of that approach, you learn something new everyday.

Stay safe and have a wonderful Easter break.
 
Upvote 0

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

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