Find and display variable text within multiple cells

damiencarl

New Member
Joined
Dec 4, 2017
Messages
3
I have a set of names that all begin with the same 4 characters, but the remaining characters are variable (e.g. ABC1111, ABC2222, ABC3333...). Also, the names show up in variable columns within the thousands of lines of data (columns A-G). Is there a way to search the lines of data for variable string "ABC*" and return the entire name in a single column (G)?

A
B
C
D
E
F
G
H
data
data
data
data
data
data
ABC1111
ABC1111
data
data
data
data
data
ABC2222
data
ABC2222
data
data
data
data
data
data
data
ABC3333
ABC4444
data
data
data
data
data
data
ABC4444

<tbody>
</tbody>
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
damiencarl,

Welcome to the Board.

You might consider the following...

Code:
Sub GetNames_1033973()
Dim str As String
Dim rng As Range
Dim r As Long, c As Long
Dim arr As Variant

str = "ABC" 'Change to match your search string
Set rng = Range("A1:H" & Cells(Rows.Count, "A").End(xlUp).Row)
arr = rng.Value

For r = 1 To Cells(Rows.Count, "A").End(xlUp).Row
    For c = 1 To 7
        If InStr(arr(r, c), str) = 1 Then
            arr(r, 8) = arr(r, c)
            Exit For
        End If
    Next c
Next r

Range("A1:H" & Cells(Rows.Count, "A").End(xlUp).Row).Value = arr
End Sub

Full names will be placed in Column H, not Column G.

Cheers,

tonyyy
 
Upvote 0
  1. damiencarl,
Welcome to the Board.

You might consider the following...

Code:
Sub GetNames_1033973()
Dim str As String
Dim rng As Range
Dim r As Long, c As Long
Dim arr As Variant

str = "ABC" 'Change to match your search string
Set rng = Range("A1:H" & Cells(Rows.Count, "A").End(xlUp).Row)
arr = rng.Value

For r = 1 To Cells(Rows.Count, "A").End(xlUp).Row
    For c = 1 To 7
        If InStr(arr(r, c), str) = 1 Then
            arr(r, 8) = arr(r, c)
            Exit For
        End If
    Next c
Next r

Range("A1:H" & Cells(Rows.Count, "A").End(xlUp).Row).Value = arr
End Sub

Full names will be placed in Column H, not Column G.

Cheers,

tonyyy

Thanks Tony, but where would I place this code within the spreadsheet to return the values in column H?
 
Upvote 0
Thanks Tony, but where would I place this code within the spreadsheet to return the values in column H?
 
Upvote 0
Is there a way to search the lines of data for variable string "ABC*" and return the entire name in a single column (G)?

Hi, here is a formula option you can try - note: note sure where ABC3333 came from for your third row of example data.


Excel 2013/2016
ABCDEFGH
1ABCDEFGH
2datadatadatadatadatadataABC1111ABC1111
3datadatadatadatadataABC2222dataABC2222
4datadatadatadatadatadatadata#N/A
5ABC4444datadatadatadatadatadataABC4444
Sheet1
Cell Formulas
RangeFormula
H2=INDEX(A2:G2,MATCH("ABC*",A2:G2,0))
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,794
Members
448,994
Latest member
rohitsomani

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