Lookup Formula for Nth Line in Wrapped Text

legalhustler

Well-known Member
Joined
Jun 5, 2014
Messages
1,168
Office Version
  1. 365
Platform
  1. Windows
I have the following text wrapped with a line break in a single cell:

ABC 1232
DEF 456
GHI 78910

I want a lookup formula to just return DEF 456? Can someone help.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Not sure about a formula, but this custom function should work.

Code:
Function NthLine(s As String, pos As Integer) As String
Dim AR() As String
AR = Split(s, Chr(10))
NthLine = AR(pos - 1)
End Function

Then the formula would look like = NthLine(A1,2)
 
Upvote 0
The line break would be Code 10 so you would need to search for CHAR(10) for the 1st stop, then find the 2nd CHAR(10) for the end
 
Upvote 0
Maybe...


A
B
C
D
1
Name​
Text​
2
John​
ABC 1232
DEF 456
GHI 78910​
3
Mary​
ABC 1232
XXX 456
CCC 1234​
4
Richard​
ABC 1232
XYZ 78910
ZZZ 9876​
5
6
Lookup​
Result​
7
John​
DEF 456​
8
Mary​
XXX 456​
9
Richard​
XYZ 78910​

<tbody>
</tbody>


Formula in D6 copied down
=TRIM(MID(SUBSTITUTE(VLOOKUP(C7,A:B,2,0),CHAR(10),REPT(" ",200)),SEARCH(CHAR(10),VLOOKUP(C7,A:B,2,0))+1,400))

Hope this helps

M.
 
Upvote 0
Generic formula


A
B
C
D
E
1
Name​
Text​
2
John​
ABC 1232
DEF 456
GHI 78910​
3
Mary​
BCD 2222
XXX 456
CCC 1234​
4
Richard​
CDE 3333
XYZ 78910
ZZZ 9876​
5
6
Nth​
Lookup​
Result​
7
3​
John​
GHI 78910​
8
1​
Mary​
BCD 2222​
9
2​
Richard​
XYZ 78910​

Criteria in C7:D9

Formula in E7 copied down
=TRIM(MID(SUBSTITUTE(CHAR(10)&VLOOKUP(D7,A:B,2,0),CHAR(10),REPT(" ",200)),C7*200,200))

M.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

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