Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 'Properise' text strings using VBA


Hi all,

Note: in VBA and not using Excel's built in functions

Quite simply (she says), I want to capitalise a person's name (fo
example).
So an example might be that Range("A1") contains the name 'mr john ala
smith'. Using VBA , I would want this string replaced with 'Mr Joh
Alan Smith'.

My program basically inputs a text file, seeks out the lines tha
contain contact details and I want to tidy up the lines prior t
populating a spreadsheet.

In the following example, let's assume the following is the text I nee
to format/ tidy up.

1) mr John aLAN smith,
2) 10b the Crescent
3) norwich.
4) England

Line 1 would become Mr John Alan Smith
Line 2 would become 10b The Crescent
Line 3 would become Norwich
Line 4 would become England

Has anyone already written a little routine that will work its wa
through a string doing the necessary on route like removing fullstops
capitalising where expected, etc?

Anyone's help would be much appreciated

Thanks

Rie

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 'Properise' text strings using VBA

v1= "mr John aLAN smith, 10b the Crescent, norwich. England"


? strconv(v1,vbProperCase)
Mr John Alan Smith, 10b The Crescent, Norwich. England

Application.Trim uses the Excel trim function

Application.Substitute uses the Excel substitue function - in xl2000 and
later, VBA has added a similar replace function

So that gets part of it.


--
Regards,
Tom Ogilvy


"Rier" wrote in message
...

Hi all,

Note: in VBA and not using Excel's built in functions

Quite simply (she says), I want to capitalise a person's name (for
example).
So an example might be that Range("A1") contains the name 'mr john alan
smith'. Using VBA , I would want this string replaced with 'Mr John
Alan Smith'.

My program basically inputs a text file, seeks out the lines that
contain contact details and I want to tidy up the lines prior to
populating a spreadsheet.

In the following example, let's assume the following is the text I need
to format/ tidy up.

1) mr John aLAN smith,
2) 10b the Crescent
3) norwich.
4) England

Line 1 would become Mr John Alan Smith
Line 2 would become 10b The Crescent
Line 3 would become Norwich
Line 4 would become England

Has anyone already written a little routine that will work its way
through a string doing the necessary on route like removing fullstops,
capitalising where expected, etc?

Anyone's help would be much appreciated

Thanks

Rier


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 'Properise' text strings using VBA

Rier
try this - it works on selected text.

Sub Txt()
Dim c
For Each c In Selection
c.Value = Application.WorksheetFunction.Proper(c)
Next c
End Sub

Peter Atherton
-----Original Message-----

Hi all,

Note: in VBA and not using Excel's built in functions

Quite simply (she says), I want to capitalise a person's

name (for
example).
So an example might be that Range("A1") contains the

name 'mr john alan
smith'. Using VBA , I would want this string replaced

with 'Mr John
Alan Smith'.

My program basically inputs a text file, seeks out the

lines that
contain contact details and I want to tidy up the lines

prior to
populating a spreadsheet.

In the following example, let's assume the following is

the text I need
to format/ tidy up.

1) mr John aLAN smith,
2) 10b the Crescent
3) norwich.
4) England

Line 1 would become Mr John Alan Smith
Line 2 would become 10b The Crescent
Line 3 would become Norwich
Line 4 would become England

Has anyone already written a little routine that will

work its way
through a string doing the necessary on route like

removing fullstops,
capitalising where expected, etc?

Anyone's help would be much appreciated

Thanks

Rier


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 'Properise' text strings using VBA

Rier

Sorry, I was tiered when I tried answering your question.
Here is a working procedure.

Sub CleanText()
Dim c
Dim l As Integer
For Each c In Selection
c.Select
l = Len(c)
c.Value = Trim(c)
If InStr(l, c, Chr(44), 1) Or InStr(l, c, Chr(46), 1)
Then
c.Value = Trim(Left(c, Len(c) - 1))
c.Value = Application.WorksheetFunction.Proper(c)
Else
c.Value = Application.WorksheetFunction.Proper(c)
End If
Next c

End Sub

I saw Tom's reply and it looks as though the the line
c.Value = Application.WorksheetFunction.Proper(c)
can be simplified.

Regards
Peter Atherton
-----Original Message-----

Hi all,

Note: in VBA and not using Excel's built in functions

Quite simply (she says), I want to capitalise a person's

name (for
example).
So an example might be that Range("A1") contains the

name 'mr john alan
smith'. Using VBA , I would want this string replaced

with 'Mr John
Alan Smith'.

My program basically inputs a text file, seeks out the

lines that
contain contact details and I want to tidy up the lines

prior to
populating a spreadsheet.

In the following example, let's assume the following is

the text I need
to format/ tidy up.

1) mr John aLAN smith,
2) 10b the Crescent
3) norwich.
4) England

Line 1 would become Mr John Alan Smith
Line 2 would become 10b The Crescent
Line 3 would become Norwich
Line 4 would become England

Has anyone already written a little routine that will

work its way
through a string doing the necessary on route like

removing fullstops,
capitalising where expected, etc?

Anyone's help would be much appreciated

Thanks

Rier


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/

.

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
find and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
Looking for Text strings Scats Excel Worksheet Functions 3 March 24th 10 11:38 PM
VLookup and text strings bmac Excel Discussion (Misc queries) 3 February 18th 10 10:25 PM
Comparing text strings Comparing columns with text Excel Worksheet Functions 5 November 28th 09 07:43 PM
Formulas are becoming text strings FrustratedinBoston Excel Discussion (Misc queries) 2 March 10th 09 12:37 PM


All times are GMT +1. The time now is 09:43 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"