View Single Post
  #21   Report Post  
Posted to microsoft.public.excel.misc
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Select specific text in cell

On Sat, 16 Feb 2008 11:09:37 -0500, "Rick Rothstein \(MVP - VB\)"
wrote:

Actually, neither your one liner nor my longer variants will work if
filename
includes a "-". For that, we need something like:

==============================
Option Explicit
Function fn(str As String) As String
Dim s1() As String
s1 = Split(str, "\")
s1 = Split(s1(UBound(s1)), "-")
ReDim Preserve s1(UBound(s1) - 1)
fn = Trim(Join(s1, "-"))
End Function
===========================


And, of course, the above would not work if the description itself
contained a dash.


In thinking a little more about this question, it would appear, given the
structure the OP has adopted, that **at least one** of the following must be
true or the OP cannot have a fool-proof parser... the filename can never
have a dash, or it can never have a space/dash/space combination in it, or
it can never have just a plain space in it (which would further require a
space always be present after the filename), or the description cannot have
a backslash in it... one of these must be true in order to create a parser
(one-liner or not) that would always work.

Rick


Expanding -- it would certainly be possible for a parser in which the "\"
preceding the filename was optional
--ron