PC Review


Reply
Thread Tools Rate Thread

Delete All Characters in Text String After xxxxx - HELP!

 
 
Paige
Guest
Posts: n/a
 
      22nd Jul 2008
I have a column of data like:

2345 1st Street PO Box 123
12 South Boulevard Mr. Smith
3241 East Tenth Drive PO123123123

Need to go down the column and wherever it finds the word 'street',
'boulevard' or 'drive', delete all the characters AFTER that word. Can
someone help with a VBA resolution to this please?
 
Reply With Quote
 
 
 
 
Wigi
Guest
Posts: n/a
 
      22nd Jul 2008
You don't need VBA code for this.

Use column B to see at which character the word Street occurs (if it
occurs). In columns C & D, do the same for the 2 other words. In column E,
ask for the minimum of the 3 cells to the left. Lastly, column F, using the
LEFT and LEN functions, get the x left most characters of column A.



--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Paige" wrote:

> I have a column of data like:
>
> 2345 1st Street PO Box 123
> 12 South Boulevard Mr. Smith
> 3241 East Tenth Drive PO123123123
>
> Need to go down the column and wherever it finds the word 'street',
> 'boulevard' or 'drive', delete all the characters AFTER that word. Can
> someone help with a VBA resolution to this please?

 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      22nd Jul 2008
Something like this. Just fill in your Boulevard and Drive code.

Sub test()

Dim i As Long
Dim arr
Dim lPos As Long

arr = Range(Cells(1), Cells(10, 1))

For i = 1 To UBound(arr)
lPos = InStr(1, UCase(arr(i, 1)), "STREET", vbBinaryCompare)
If lPos > 0 Then
arr(i, 1) = Left$(arr(i, 1), lPos + 5)
End If
Next i

Range(Cells(1), Cells(10, 1)) = arr

End Sub


RBS

"Paige" <(E-Mail Removed)> wrote in message
news:C648C050-DC8F-4959-9924-(E-Mail Removed)...
>I have a column of data like:
>
> 2345 1st Street PO Box 123
> 12 South Boulevard Mr. Smith
> 3241 East Tenth Drive PO123123123
>
> Need to go down the column and wherever it finds the word 'street',
> 'boulevard' or 'drive', delete all the characters AFTER that word. Can
> someone help with a VBA resolution to this please?


 
Reply With Quote
 
Paige
Guest
Posts: n/a
 
      22nd Jul 2008
Thanks, Wigi. I can do with formulas, but it is ugly because there are
actually more than just 3 things to look for, so really would like a VBA
solution if possible.

"Wigi" wrote:

> You don't need VBA code for this.
>
> Use column B to see at which character the word Street occurs (if it
> occurs). In columns C & D, do the same for the 2 other words. In column E,
> ask for the minimum of the 3 cells to the left. Lastly, column F, using the
> LEFT and LEN functions, get the x left most characters of column A.
>
>
>
> --
> Wigi
> http://www.wimgielis.be = Excel/VBA, soccer and music
>
>
> "Paige" wrote:
>
> > I have a column of data like:
> >
> > 2345 1st Street PO Box 123
> > 12 South Boulevard Mr. Smith
> > 3241 East Tenth Drive PO123123123
> >
> > Need to go down the column and wherever it finds the word 'street',
> > 'boulevard' or 'drive', delete all the characters AFTER that word. Can
> > someone help with a VBA resolution to this please?

 
Reply With Quote
 
Wigi
Guest
Posts: n/a
 
      22nd Jul 2008
Hello there

Here you go.


Sub stripafterwords()

Const sWord1 As String = "street"
Const sWord2 As String = "boulevard"
Const sWord3 As String = "drive"

Dim r As Range


For Each r In Range("A1", Range("A" & Rows.Count).End(xlUp))

r.Value = afterdeleting(CStr(r.Value), sWord1)
r.Value = afterdeleting(CStr(r.Value), sWord2)
r.Value = afterdeleting(CStr(r.Value), sWord3)

Next

End Sub

Function afterdeleting(s As String, sSpecialWord As String) As String

Dim i As Long

i = InStr(s, sSpecialWord)

If i Then
afterdeleting = Trim(Left(s, i - 1 + Len(sSpecialWord)))
Else
afterdeleting = s
End If

End Function



--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Paige" wrote:

> Thanks, Wigi. I can do with formulas, but it is ugly because there are
> actually more than just 3 things to look for, so really would like a VBA
> solution if possible.
>
> "Wigi" wrote:
>
> > You don't need VBA code for this.
> >
> > Use column B to see at which character the word Street occurs (if it
> > occurs). In columns C & D, do the same for the 2 other words. In column E,
> > ask for the minimum of the 3 cells to the left. Lastly, column F, using the
> > LEFT and LEN functions, get the x left most characters of column A.
> >
> >
> >
> > --
> > Wigi
> > http://www.wimgielis.be = Excel/VBA, soccer and music
> >
> >
> > "Paige" wrote:
> >
> > > I have a column of data like:
> > >
> > > 2345 1st Street PO Box 123
> > > 12 South Boulevard Mr. Smith
> > > 3241 East Tenth Drive PO123123123
> > >
> > > Need to go down the column and wherever it finds the word 'street',
> > > 'boulevard' or 'drive', delete all the characters AFTER that word. Can
> > > someone help with a VBA resolution to this please?

 
Reply With Quote
 
Paige
Guest
Posts: n/a
 
      22nd Jul 2008
WOW - You are WUNDERBAR!! Thank you thank you!

"Wigi" wrote:

> Hello there
>
> Here you go.
>
>
> Sub stripafterwords()
>
> Const sWord1 As String = "street"
> Const sWord2 As String = "boulevard"
> Const sWord3 As String = "drive"
>
> Dim r As Range
>
>
> For Each r In Range("A1", Range("A" & Rows.Count).End(xlUp))
>
> r.Value = afterdeleting(CStr(r.Value), sWord1)
> r.Value = afterdeleting(CStr(r.Value), sWord2)
> r.Value = afterdeleting(CStr(r.Value), sWord3)
>
> Next
>
> End Sub
>
> Function afterdeleting(s As String, sSpecialWord As String) As String
>
> Dim i As Long
>
> i = InStr(s, sSpecialWord)
>
> If i Then
> afterdeleting = Trim(Left(s, i - 1 + Len(sSpecialWord)))
> Else
> afterdeleting = s
> End If
>
> End Function
>
>
>
> --
> Wigi
> http://www.wimgielis.be = Excel/VBA, soccer and music
>
>
> "Paige" wrote:
>
> > Thanks, Wigi. I can do with formulas, but it is ugly because there are
> > actually more than just 3 things to look for, so really would like a VBA
> > solution if possible.
> >
> > "Wigi" wrote:
> >
> > > You don't need VBA code for this.
> > >
> > > Use column B to see at which character the word Street occurs (if it
> > > occurs). In columns C & D, do the same for the 2 other words. In column E,
> > > ask for the minimum of the 3 cells to the left. Lastly, column F, using the
> > > LEFT and LEN functions, get the x left most characters of column A.
> > >
> > >
> > >
> > > --
> > > Wigi
> > > http://www.wimgielis.be = Excel/VBA, soccer and music
> > >
> > >
> > > "Paige" wrote:
> > >
> > > > I have a column of data like:
> > > >
> > > > 2345 1st Street PO Box 123
> > > > 12 South Boulevard Mr. Smith
> > > > 3241 East Tenth Drive PO123123123
> > > >
> > > > Need to go down the column and wherever it finds the word 'street',
> > > > 'boulevard' or 'drive', delete all the characters AFTER that word. Can
> > > > someone help with a VBA resolution to this please?

 
Reply With Quote
 
Wigi
Guest
Posts: n/a
 
      22nd Jul 2008
No thanks. You're welcome.


--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Paige" wrote:

> WOW - You are WUNDERBAR!! Thank you thank you!
>
> "Wigi" wrote:
>
> > Hello there
> >
> > Here you go.
> >
> >
> > Sub stripafterwords()
> >
> > Const sWord1 As String = "street"
> > Const sWord2 As String = "boulevard"
> > Const sWord3 As String = "drive"
> >
> > Dim r As Range
> >
> >
> > For Each r In Range("A1", Range("A" & Rows.Count).End(xlUp))
> >
> > r.Value = afterdeleting(CStr(r.Value), sWord1)
> > r.Value = afterdeleting(CStr(r.Value), sWord2)
> > r.Value = afterdeleting(CStr(r.Value), sWord3)
> >
> > Next
> >
> > End Sub
> >
> > Function afterdeleting(s As String, sSpecialWord As String) As String
> >
> > Dim i As Long
> >
> > i = InStr(s, sSpecialWord)
> >
> > If i Then
> > afterdeleting = Trim(Left(s, i - 1 + Len(sSpecialWord)))
> > Else
> > afterdeleting = s
> > End If
> >
> > End Function
> >
> >
> >
> > --
> > Wigi
> > http://www.wimgielis.be = Excel/VBA, soccer and music
> >
> >
> > "Paige" wrote:
> >
> > > Thanks, Wigi. I can do with formulas, but it is ugly because there are
> > > actually more than just 3 things to look for, so really would like a VBA
> > > solution if possible.
> > >
> > > "Wigi" wrote:
> > >
> > > > You don't need VBA code for this.
> > > >
> > > > Use column B to see at which character the word Street occurs (if it
> > > > occurs). In columns C & D, do the same for the 2 other words. In column E,
> > > > ask for the minimum of the 3 cells to the left. Lastly, column F, using the
> > > > LEFT and LEN functions, get the x left most characters of column A.
> > > >
> > > >
> > > >
> > > > --
> > > > Wigi
> > > > http://www.wimgielis.be = Excel/VBA, soccer and music
> > > >
> > > >
> > > > "Paige" wrote:
> > > >
> > > > > I have a column of data like:
> > > > >
> > > > > 2345 1st Street PO Box 123
> > > > > 12 South Boulevard Mr. Smith
> > > > > 3241 East Tenth Drive PO123123123
> > > > >
> > > > > Need to go down the column and wherever it finds the word 'street',
> > > > > 'boulevard' or 'drive', delete all the characters AFTER that word. Can
> > > > > someone help with a VBA resolution to this please?

 
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
Delete X characters from end of string =?Utf-8?B?Sm9obiBE?= Microsoft Access Queries 3 19th Jan 2007 07:20 AM
Macro to delete row based on criteria (first few characters of string) delapp@hotmail.com Microsoft Excel Programming 5 15th May 2006 06:11 PM
Re: want to remove all text characters equal to one character in length from text string CLR Microsoft Excel Worksheet Functions 0 18th Apr 2005 09:56 PM
Re: want to remove all text characters equal to one character in length from text string CLR Microsoft Excel Worksheet Functions 0 18th Apr 2005 12:25 AM
Delete characters from a string Ron Microsoft Excel Programming 7 19th Feb 2004 04:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:52 PM.