Microsoft Excel - Search A String in Excel Using VBA

Asked By Rajender Prasad on 20-May-13 04:21 PM
Dear All,

I have below scenario. Please help me out.

in Column A, i have the data which is copy pasted from a website.
That data may contain, any of the below like ABCD, EFGH, IJKL, MNOP..

I need to search in the data whether any of the ABCD, EFGH, IJKL, MNOP..is existed or not, if existed, I want to select that value.

I am able to do it, but if ABCD is not there then is showing an error at run time.

please help

Regards,
prasad
Harry Boughen replied to Rajender Prasad on 20-May-13 05:28 PM
Hello Prasad,
Can you give the piece of code that you are using for the extraction?
Regards
Harry
Rajender Prasad replied to Harry Boughen on 21-May-13 08:42 AM

I am using the below code to find the search, if value not found, am getting an error.

But wat I require is, watever the string am searching for, if its there the only string has to be extracted from the whole string.

please help


Function FindText(SearchString As String)

'    Dim cl As Range
'    Dim ws As Worksheet
''    Workbooks("cosmos access thru vba.xlsm").Sheets(5).Activate
'    'Sheets("calcSheet").Activate
'
'    Set ws = Worksheets("Sheet2")
'    ActiveSheet.Range("A1").Select
'    Application.FindFormat.Clear
'
'' Find first instance on sheet
''On Error GoTo Handler:
'
'    Set cl = ws.Cells.Find(What:=SearchString, After:=ws.Cells(1, 1), _
'    LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
'    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
'    cl.Activate

            
End Function