Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default remove text after character

On Mon, 2 Nov 2009 12:04:01 -0800, Dave L
wrote:

I'm writing a macro that will do a number of things, but I'm having trouble
with one part of it. I have a column that has text in it's values. What i
want to do is remove any text that is in parenthesis. So I a basically need
to remove anything after the "(" in a text string. If there are no
parenthesis in the cell then it should leave it alone. I'm sure this is
pretty easy, but I can't get the Find method to combine with Left to make is
work.


Your description and subject describe two different things.

To remove all text after some token (and to also remove the token and any
trailing spaces), you could use code such as:

===================
Function RemTextAfter(s As String, token As String) As String
RemTextAfter = Trim(Split(s, token)(0))
End Function
====================


However, if you want to remove all the text within parentheses, and I am
assuming you also want to remove the parentheses and leave only one space
between what is remaining, then:

=================================
Option Explicit
Function RemTextInParenth(s As String) As String
Dim re As Object
Const sPat As String = "\s*\([^)]+\)"

Set re = CreateObject("vbscript.regexp")
re.Pattern = sPat
re.Global = True

RemTextInParenth = re.Replace(s, "")
End Function
=================================

will handle multiple instances of text within parentheses. If there might be a
parentheses at the start of the string, change the next to last line to:

RemTextInParenth = Trim(re.Replace(s, ""))
--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I remove a text character from an excel cell? Mark Excel Worksheet Functions 3 October 14th 06 12:21 AM
Remove last character of text string Grant Excel Worksheet Functions 2 September 29th 05 05:17 PM
How do I remove all text in a cell after a specific character? Erik Millerd Excel Worksheet Functions 1 July 13th 05 03:17 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 09:56 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 12:25 AM


All times are GMT +1. The time now is 05:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"