Search for Specific Value - For Every Match, Combine into One Cell.

FrEaK_aCcIdEnT

Board Regular
Joined
May 1, 2012
Messages
104
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I have been trying to figure this out. I need to search a spreadsheet for a record. Then for every cell that it find with the record, offset to locate the corresponding data, Then repeat until it has found all records and combine them all into one cell as the output.

Searching, offset, setting the variable for a single record, is not problem. Just never tried to put multiple records together before.

Search for all "1" values and every record that matches value & char(10) & value. Could be 1 hit, could be 20 hits. Just need them all to end up in the same cell with a page break. Any takers? :)

1721683610479.png
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
what version of excel do you have? Please update your user profile so it shows up on your chat button.
Thanks in advance?

Do you want it with the line breaks?
 
Upvote 0
See if this does what you need:
VBA Code:
Private Sub ComboNumVal()
Dim i As Long
Dim output As String

For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
    If Range("A" & i) = 1 Then
        output = output & Chr(10) & Range("B" & i)
    End If
Next i

output = Replace(output, Chr(10), "", , 1)
Range("B15") = output
End Sub

Book1
AB
1Col1Col2
21This
31Is
41What
52This
62How
72Me
81I
91Need
105You
116Too
12
13
14
15This Is What I Need
Sheet3
 
Upvote 0
Here is a formula version:

HEre is a 365 version:

Book1
ABC
1
21This
31Is
41What
52This
62How
72Me
81I
91Need
105You
116Too
12This Is What I Need
Sheet3
Cell Formulas
RangeFormula
C12C12=TEXTJOIN(CHAR(10),1,FILTER($B$2:$B$11,$A$2:$A$11=1))
 
Upvote 0
an alternative is to use Power Pivot and build a measure

Book5
ABCDE
1Col1Col2Row LabelsConcat2
21this1this is what I Need
31is2this How Me You Too
41what
52This
62How
72Me
81I
91Need
102You
112Too
Sheet1
 

Attachments

  • Screenshot 2024-07-22 155130.png
    Screenshot 2024-07-22 155130.png
    53.1 KB · Views: 7
Upvote 0
See if this does what you need:
VBA Code:
Private Sub ComboNumVal()
Dim i As Long
Dim output As String

For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
    If Range("A" & i) = 1 Then
        output = output & Chr(10) & Range("B" & i)
    End If
Next i

output = Replace(output, Chr(10), "", , 1)
Range("B15") = output
End Sub

Book1
AB
1Col1Col2
21This
31Is
41What
52This
62How
72Me
81I
91Need
105You
116Too
12
13
14
15This Is What I Need
Sheet3
It's my fault for not being 100% clear. I thought I could get away with using 1, 2, 3 in column A as the example. Here is by actual code. VIN is declared properly. Using it all throughout the module. I am trying to find the VIN in L over and over. Then pull the data from AC that corresponds with VIN match. I am getting a type mismatch error on the line below. I have tried .value, .text, and nothing added. All same result. I know it's probably something simple, but my brain is fried...

1721688095378.png
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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