VBA Find Instances of Text in Range then Parse and Offest Result

adavid

Board Regular
Joined
May 28, 2014
Messages
145
I need to search a range ("G3:Z") searching for the text "ECP". The text could be in any cell of the range per line item and would used in a sentence like structure.
The text could also be in varying formats e.g. ECP# 123456, ECP - 123456, ECP # 123456, ECP–123456, etc. (note the En dash is not a hyphen).
If found, I then need the parsed value to be entered into the same row from which the result was found, but entered into column "E" of the same row.

Below is what I was thinking (please excuse the incongruency; it's Friday or as I call it "Brain-Fried-day")
Code:
Sub findECP()

Dim splitString As String
Dim splitStringLeft As String
Dim splitStringRight As String
Dim pos As Long
 
splitString = "111111-111*1"
 
pos = InStr(splitString, "*")
 
With Worksheets(10).Range("G3:Z")
    Set c = .Find("ECP", LookIn:=xlValues)
 

  If Not c Is Nothing Then ' check delimiter is found
        firstAddress = c.Address
        splitString = firstAddress.Value
        pos = InStr(splitString, "ECP")
        splitStringLeft = Left(splitString, pos - 1)
        splitStringRight = Mid(splitString, , (pos + 10) - Right(pos, Find(" ")))
 
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Maybe:

Code:
Sub adavid()
Dim rcell As Range
For Each rcell In Range("G3:Z" & Range("Z" & Rows.Count).End(3).row)
    If rcell Like "*ECP*" Then Cells(rcell.row, "E") = rcell
Next rcell
End Sub
 
Upvote 0
Thank you for the reply, but I got a "type mismatch" error at "If rcell Like "*ECP*" Then"
Also if and ECP value is found, I only need the ECP number, not the entire contents of the the cell its was found in.
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,085
Members
449,206
Latest member
ralemanygarcia

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