Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Change code HELP. Sentence Case

The below code changes the text in the designated range to sentence case,
however it ONLY does this for the first word.
How can i adapt it to do this to EACH word in the cell?

Sub SentenceCase()
Dim WS As Worksheet
Dim cell As Range

For Each WS In ThisWorkbook.worksheets
For Each cell In WS.Range("a8:A30,c7:r7")
s = cell.Value
Start = True
For i = 1 To Len(s)
ch = Mid(s, i, 1)
Select Case ch
Case "."
Start = True
Case "?"
Start = True
Case "a" To "z"
If Start Then ch = UCase(ch): Start = False
Case "A" To "Z"
If Start Then Start = False Else ch = LCase(ch)
End Select
Mid(s, i, 1) = ch
Next
cell.Value = s
Next
Next
End Sub

Regards
Corey....
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Change code HELP. Sentence Case

Hi Corey,

Try:

'=============
Public Sub SentenceCase()
Dim WS As Worksheet
Dim rng As Range
Dim rCell As Range
Const sAddress = ("A8:A30,C7:R7")

For Each WS In ThisWorkbook.Worksheets
On Error Resume Next
Set rng = WS.Range(sAddress). _
SpecialCells(xlConstants, xlTextValues)
On Error GoTo 0
If Not rng Is Nothing Then
For Each rCell In rng.Cells
With rCell
.Value = Application.Proper(.Value)
End With
Next rCell
End If
Next WS
End Sub
'<<=============


---
Regards,
Norman

"Corey" wrote in message
...
The below code changes the text in the designated range to sentence case,
however it ONLY does this for the first word.
How can i adapt it to do this to EACH word in the cell?

Sub SentenceCase()
Dim WS As Worksheet
Dim cell As Range

For Each WS In ThisWorkbook.worksheets
For Each cell In WS.Range("a8:A30,c7:r7")
s = cell.Value
Start = True
For i = 1 To Len(s)
ch = Mid(s, i, 1)
Select Case ch
Case "."
Start = True
Case "?"
Start = True
Case "a" To "z"
If Start Then ch = UCase(ch): Start = False
Case "A" To "Z"
If Start Then Start = False Else ch = LCase(ch)
End Select
Mid(s, i, 1) = ch
Next
cell.Value = s
Next
Next
End Sub

Regards
Corey....


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Change code HELP. Sentence Case

thanks Norman
Too easy

Corey....

"Norman Jones" wrote in message
...
Hi Corey,

Try:

'=============
Public Sub SentenceCase()
Dim WS As Worksheet
Dim rng As Range
Dim rCell As Range
Const sAddress = ("A8:A30,C7:R7")

For Each WS In ThisWorkbook.Worksheets
On Error Resume Next
Set rng = WS.Range(sAddress). _
SpecialCells(xlConstants, xlTextValues)
On Error GoTo 0
If Not rng Is Nothing Then
For Each rCell In rng.Cells
With rCell
.Value = Application.Proper(.Value)
End With
Next rCell
End If
Next WS
End Sub
'<<=============


---
Regards,
Norman

"Corey" wrote in message
...
The below code changes the text in the designated range to sentence case,
however it ONLY does this for the first word.
How can i adapt it to do this to EACH word in the cell?

Sub SentenceCase()
Dim WS As Worksheet
Dim cell As Range

For Each WS In ThisWorkbook.worksheets
For Each cell In WS.Range("a8:A30,c7:r7")
s = cell.Value
Start = True
For i = 1 To Len(s)
ch = Mid(s, i, 1)
Select Case ch
Case "."
Start = True
Case "?"
Start = True
Case "a" To "z"
If Start Then ch = UCase(ch): Start = False
Case "A" To "Z"
If Start Then Start = False Else ch = LCase(ch)
End Select
Mid(s, i, 1) = ch
Next
cell.Value = s
Next
Next
End Sub

Regards
Corey....



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
convert text to sentence case Jacqueline Excel Discussion (Misc queries) 3 January 20th 09 10:09 PM
Sentence Case Alex Excel Discussion (Misc queries) 2 August 21st 08 09:45 PM
How do I change case to sentence case in groups in excel? Pinetree Excel Discussion (Misc queries) 3 May 30th 07 05:55 AM
How to change case on a spreadsheet from Caps to Sentence? Mamacsee Excel Discussion (Misc queries) 1 July 5th 05 09:23 PM
Change Capitals to Sentence Case do Excel Discussion (Misc queries) 2 March 29th 05 02:31 AM


All times are GMT +1. The time now is 04:30 PM.

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

About Us

"It's about Microsoft Excel"