Try This One : See the attached file..
Function GetFinal(rngData As Range) Dim bytICounter As Byte Dim F As String Dim l As String Dim bytDel As Byte blnflag = False i = 1 strData = WorksheetFunction.Substitute(rngData.Value, "-", "") bytDel = Len(rngData.Value) - Len(WorksheetFunction.Substitute(rngData.Value, "-", "")) For bytICounter = 1 To Len(strData) F = Mid(strData, bytICounter, 3) l = Mid(strData, ((Len(strData) - 3 * i) + 1), 3) If F = l Then blnflag = True End If i = i + 1 If i >= (bytDel - 1) Then Exit For Next bytICounter If blnflag = True Then GetFinal = Mid(strData, ((Len(strData) - 3 * (i)) + 1), 3) Else GetFinal = Right(strData, 3) End If End Function From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] On Behalf Of Kris Sent: Dec/Sat/2011 02:56 To: excel-macros@googlegroups.com Subject: Re: $$Excel-Macros$$ To Extract a text with Conditions Hi Rajan, The route are different. DMS-BAH and BAH-DMM Kris -- FORUM RULES (934+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ---------------------------------------------------------------------------- -------------------------- To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (934+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com
Sample.xlsm
Description: application/vnd.ms-excel.sheet.macroenabled.12