PC Review


Reply
Thread Tools Rate Thread

How do I find last occurence of a character in a text string in Ex

 
 
jten
Guest
Posts: n/a
 
      24th Aug 2009
I am looking for the last occurrence of a blank in a text string so that I
can parse the string
 
Reply With Quote
 
 
 
 
RB Smissaert
Guest
Posts: n/a
 
      24th Aug 2009
The VBA function InStrRev will do that.

RBS


"jten" <(E-Mail Removed)> wrote in message
news:4F96E3D1-D4D0-4C0D-ADC6-(E-Mail Removed)...
>I am looking for the last occurrence of a blank in a text string so that I
> can parse the string


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      24th Aug 2009
Hi,

You posted in programming so maybe you want this.

mypos = InStrRev(Range("A1"), " ")

bur if you wanted a worksheet solution try this

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))

Mike

"jten" wrote:

> I am looking for the last occurrence of a blank in a text string so that I
> can parse the string

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      24th Aug 2009
Since you are asking about finding the last blank in a text string so that
you can parse the string, I am assuming you are looking to obtain the last
word in the string. If that is the case, you can do it like this...

Programming Method #1
========================
Txt = "Your Text String"
LastWord = Mid(Txt, InStrRev(Txt, " ") + 1)

Programming Method #2
========================
Txt = "Your Text String"
Arr = Split(Txt)
LastWord = Arr(UBound(Arr))

When you Dim your variables, Programming Method #2 can use either a Variant
or a String array for the Arr variable shown.

Formula Method
========================
=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99))

The formula method assumes your text will be no longer than 99 characters.
If it will be longer, then change the two 99's to a number larger than the
maximum length.

--
Rick (MVP - Excel)


"jten" <(E-Mail Removed)> wrote in message
news:4F96E3D1-D4D0-4C0D-ADC6-(E-Mail Removed)...
>I am looking for the last occurrence of a blank in a text string so that I
> can parse the string


 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      24th Aug 2009
as well as the two responses already received, you could also use the SPLIT
function

This is particularly useful if you want to see how many items are in the text

eg
Option Explicit
Sub SplitDemo()
Dim text As String
Dim var As Variant
text = "There are four words"
var = Split(text, " ")

MsgBox "text has " & UBound(var, 1) + 1 & " items"

Dim index As Long
index = UBound(var, 1)
MsgBox "The #" & index & " item =" & var(index)

End Sub


"jten" wrote:

> I am looking for the last occurrence of a blank in a text string so that I
> can parse the string

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find last occurance of character in text string =?Utf-8?B?SkRheTAx?= Microsoft Excel Worksheet Functions 2 14th Feb 2006 04:29 PM
Re: How to find the last occurence of a character Daniel.M Microsoft Excel Worksheet Functions 1 23rd Jun 2004 05:45 PM
Re: How to find the last occurence of a character William Microsoft Excel Worksheet Functions 0 23rd Jun 2004 03:38 PM
Re: How to find the last occurence of a character Andy B Microsoft Excel Worksheet Functions 0 23rd Jun 2004 03:26 PM
backwards find function to find character in a string of text Ashleigh K. Microsoft Excel Programming 1 14th Jan 2004 04:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:36 PM.