Solved

Word VBA Delete last word from string

Posted on 2012-03-12
2
2,468 Views
Last Modified: 2012-03-14
Hi experts

I need to delete the last word from my string.

I have the code below that tells me the last word in the string, but I can't work out how to manipulate it so that I end up with my string equalling "The quick brown" rather than "The quick brown fox.

Dim Str As String
Str = "The quick brown fox"
MsgBox Right(Str, Len(Str) - (InStrRev(Str, " ") - 1))

Open in new window

0
Comment
Question by:Fi69
2 Comments
 
LVL 11

Accepted Solution

by:
rowansmith earned 150 total points
ID: 37712964
MsgBox Left(Str,InStrRev(Str, " ") - 1)
0
 

Author Closing Comment

by:Fi69
ID: 37722886
Thank you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

792 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