Solved

Would like this function to be made to work like a MID function, but in reverse.

Posted on 2016-10-27
4
25 Views
Last Modified: 2016-10-28
I have a number of cells like this:
a2= Text to Columns - Data > Data Tools > Text to Columns
The number of dashes vary before the > symbol, but I always want to pull the data from the end of the cell up to the dash.

The function would work like this: FromEnd("-",a2) and it would return
- Data > Data Tools > Text to Columns

I could then use Mid to select after the dash.

Function Reverse(str As String) As String
    Reverse = StrReverse(Trim(str))
End Function
0
Comment
Question by:Alex972
  • 2
4 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41863291
Put this in a code module

Function GetDash(r As Range) As String

Dim intPos As Integer

intPos = InStrRev(r, "-")

GetDash = Mid(r, intPos - 1)
End Function

Open in new window

Usage:
=GetDash(A2)
0
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41863356
You may use inbuilt functions to get the desired output.
Please try this....
=TRIM(RIGHT(SUBSTITUTE(A2,"-",REPT(" ",LEN(A2))),LEN(A2)))

Open in new window

0
 

Author Closing Comment

by:Alex972
ID: 41864177
Thanks, works great.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41864188
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now