Extracting multiple words out of a single cell - where do I start?

christos75

New Member
Joined
Sep 5, 2012
Messages
2
Hi all, hope someone can help with the following. Using Excel 2016. I'll try and explain what I am trying to do as best I can.

I have a spreadsheet with a lot of data in a single column A. This could be from A1 to A500.
Each cell in the column contains a lot of text from extracted emails including auto signatures. What I want to do is to find the following word (with wildcards), "N???????L" in each cell. It always starts with N and ends with L with 7 numbers inbetween.
It could appear once in the cell and it could also appear 2 times, or 3 times or even 15 times. I want to extract all the words "N???????L" from the cell and copy to another column, each in its own row. And then do this for all cells in the column.

Is this possible?
I have not been able to find a way to do this and do not even know where to begin so I don't have a sample code of what I've tried.

Thank you.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hello,

try with

Code:
with cells(1,1)
for i = 1 to len(.value) -9
     if mid(.value,i,9) like "N#######L" then msgbox "found"
next i
end with
 
Upvote 0
You need VBA and the Like operator. InStr doesn't take wildcards (unless it changed in XL2016)

Code:
For Cellcount = 1 to 500
    MyCell = cells(CellCount,1).Value
    FoundCount = 0
    For CharCount = 1 to Len(MyCell)
        if Mid(Mycell,CharCount,9) Like "[N]???????[L]" Then
            FoundCount = FoundCount + 1
            cells(CellCount,1+FoundCount).Value = Mid(Mycell,CharCount,9)
        End if
    next CharCount
Next CellCount
 
Upvote 0
You need VBA and the Like operator. InStr doesn't take wildcards (unless it changed in XL2016)

Code:
For Cellcount = 1 to 500
    MyCell = cells(CellCount,1).Value
    FoundCount = 0
    For CharCount = 1 to Len(MyCell)
        if Mid(Mycell,CharCount,9) Like "[N]???????[L]" Then
            FoundCount = FoundCount + 1
            cells(CellCount,1+FoundCount).Value = Mid(Mycell,CharCount,9)
        End if
    next CharCount
Next CellCount

It extracts NNNNNNNNL.
 
Upvote 0
Try
"N#######L" (as in Fennek's code)
or
"N[0-9][0-9][0-9][0-9][0-9][0-9][0-9]L"
 
Last edited:
Upvote 0
You guys are awesome. It worked. THANK YOU!!!!! :):)

For CellCount = 1 To 500
Mycell = Cells(CellCount, 1).Value
FoundCount = 0
For CharCount = 1 To Len(Mycell)
If Mid(Mycell, CharCount, 9) Like "N#######L" Then
FoundCount = FoundCount + 1
Cells(CellCount, 1 + FoundCount).Value = Mid(Mycell, CharCount, 9)
End If
Next CharCount
Next CellCount
 
Upvote 0
You guys are awesome. It worked. THANK YOU!!!!! :):)

For CellCount = 1 To 500
Mycell = Cells(CellCount, 1).Value
FoundCount = 0
For CharCount = 1 To Len(Mycell)
If Mid(Mycell, CharCount, 9) Like "N#######L" Then
FoundCount = FoundCount + 1
Cells(CellCount, 1 + FoundCount).Value = Mid(Mycell, CharCount, 9)
End If
Next CharCount
Next CellCount

I think this is of very small importance from practical point of view, just to mention: your code extracts not only "words", as you have mentioned in post #1 , but extracts N1234567L also from NN1234567LIST.
 
Upvote 0
This will not find NN1234567LIST
Code:
Dim oneWord as Variant

For CellCount = 1 To 500
    Mycell = Cells(CellCount, 1).Value
    FoundCount = 0
    For Each oneWord in Split(MyCell, " ")
        If oneWord Like "N#######L" Then
            FoundCount = FoundCount + 1
            Cells(CellCount, 1 + FoundCount).Value = Mid(Mycell, CharCount, 9)
        End If
    Next oneWord
Next CellCount
 
Upvote 0

Forum statistics

Threads
1,215,646
Messages
6,126,002
Members
449,279
Latest member
Faraz5023

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