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.
Try this function:
Function remove_after_character(s As String, c As String) As String
If InStr(s, c) Then
remove_after_character = Left(s, InStr(s, c))
Else
remove_after_character = s
End If
End Function
use e.g. like this:
Cells(1,1) = remove_after_character(Cells(1,1), "(")
Hope this helps / Lars-Åke
|