Solved

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

Posted on 2016-10-27
4
30 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:Alex Campbell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

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 31

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
 
LVL 1

Author Closing Comment

by:Alex Campbell
ID: 41864177
Thanks, works great.
0
 
LVL 48

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

623 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