Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-10-27
4
Medium Priority
?
32 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
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 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 33

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 49

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

916 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