Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default error in code: capitalize first letter of a word


Hi everybody,

I want to captalize the first letter of the FIRST word in each cell of
a column.

The cell contains something like this:
a anterior view
b first cervical vertebra (atlas)
...

I'd like to habe the FIRST LETTER OF THE FIRST WORD capitalized.
(not the first letter a, b or c)

I have this code, but it does it for ALL words.

How can one stop it from doing that?


Code:
--------------------

Sub First_Letter_Cap()
i = CInt(InputBox("Which column" & vbLf & " A=1, B=2,..", "Question", "1"))
For Each cell In Worksheets("Sheet2").Columns(i).SpecialCells(xlCel lTypeConstants, 2)
strText = cell.Value
Trennzeichen = " "
posStart = InStr(1, strText, Trennzeichen)
part2 = Mid(strText, posStart + 1)
part1 = Left(strText, posStart)
cell.Value = part1 & Trim(WorksheetFunction.Proper(part2))
Next cell
End Sub

--------------------


THANKS A LOT!!!


--
JVLennox
------------------------------------------------------------------------
JVLennox's Profile: http://www.excelforum.com/member.php...o&userid=32505
View this thread: http://www.excelforum.com/showthread...hreadid=526143

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default error in code: capitalize first letter of a word

Dim Rng As Range
For Each Rng In Selection.Cells
Rng.Value = UCase(Left(Rng.Text, 1)) & Mid(Rng.Text, 2)
Next Rng



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"JVLennox"
wrote in
message
...

Hi everybody,

I want to captalize the first letter of the FIRST word in each
cell of
a column.

The cell contains something like this:
a anterior view
b first cervical vertebra (atlas)
..

I'd like to habe the FIRST LETTER OF THE FIRST WORD
capitalized.
(not the first letter a, b or c)

I have this code, but it does it for ALL words.

How can one stop it from doing that?


Code:
--------------------

Sub First_Letter_Cap()
i = CInt(InputBox("Which column" & vbLf & " A=1, B=2,..",
"Question", "1"))
For Each cell In
Worksheets("Sheet2").Columns(i).SpecialCells(xlCel lTypeConstants,
2)
strText = cell.Value
Trennzeichen = " "
posStart = InStr(1, strText, Trennzeichen)
part2 = Mid(strText, posStart + 1)
part1 = Left(strText, posStart)
cell.Value = part1 & Trim(WorksheetFunction.Proper(part2))
Next cell
End Sub

--------------------


THANKS A LOT!!!


--
JVLennox
------------------------------------------------------------------------
JVLennox's Profile:
http://www.excelforum.com/member.php...o&userid=32505
View this thread:
http://www.excelforum.com/showthread...hreadid=526143



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default error in code: capitalize first letter of a word

Hi,

Take a look at the worksheetfunction Proper()

HTH
Carim

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default error in code: capitalize first letter of a word

Sub First_Letter_Cap()
i = CInt(InputBox("Which column" & vbLf & _
" A=1, B=2,..", "Question", "1"))
For Each cell In Worksheets("Sheet2") _
.Columns(i).SpecialCells(xlCellTypeConstants, 2)
strText = cell.Value
Trennzeichen = " "
posStart = InStr(1, strText, Trennzeichen)
cell.Characters(posStart + 1, 1).Text = _
UCase(cell.Characters(posStart + 1, 1).Text)
Next cell
End Sub

--
Regards,
Tom Ogilvy

"JVLennox" wrote:


Hi everybody,

I want to captalize the first letter of the FIRST word in each cell of
a column.

The cell contains something like this:
a anterior view
b first cervical vertebra (atlas)
...

I'd like to habe the FIRST LETTER OF THE FIRST WORD capitalized.
(not the first letter a, b or c)

I have this code, but it does it for ALL words.

How can one stop it from doing that?


Code:
--------------------

Sub First_Letter_Cap()
i = CInt(InputBox("Which column" & vbLf & " A=1, B=2,..", "Question", "1"))
For Each cell In Worksheets("Sheet2").Columns(i).SpecialCells(xlCel lTypeConstants, 2)
strText = cell.Value
Trennzeichen = " "
posStart = InStr(1, strText, Trennzeichen)
part2 = Mid(strText, posStart + 1)
part1 = Left(strText, posStart)
cell.Value = part1 & Trim(WorksheetFunction.Proper(part2))
Next cell
End Sub

--------------------


THANKS A LOT!!!


--
JVLennox
------------------------------------------------------------------------
JVLennox's Profile: http://www.excelforum.com/member.php...o&userid=32505
View this thread: http://www.excelforum.com/showthread...hreadid=526143




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default error in code: capitalize first letter of a word


Hey guys thanks!

But I forgot something:

sometimes a cell can be like this:
a-c second thoracic vertebra.
d cervical spine with both vertebral arteries and the emerging spinal
nerves
e schematic coronal section, tenth week.

So, the seperator must be " " and then only the FIRST WORD shall be
capitalized.

But my code does ALL words... :-()

Code:
--------------------

Sub First_Letter_Cap()
i = CInt(InputBox("Which column" & vbLf & " A=1, B=2,..", "Question", "1"))
For Each cell In Worksheets("Sheet2").Columns(i).SpecialCells(xlCel lTypeConstants, 2)
strText = cell.Value
Trennzeichen = " "
posStart = InStr(1, strText, Trennzeichen)
part2 = Mid(strText, posStart + 1)
part1 = Left(strText, posStart)
cell.Value = part1 & Trim(WorksheetFunction.Proper(part2))
Next cell
End Sub

--------------------


--
JVLennox
------------------------------------------------------------------------
JVLennox's Profile: http://www.excelforum.com/member.php...o&userid=32505
View this thread: http://www.excelforum.com/showthread...hreadid=526143

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default error in code: capitalize first letter of a word


@ Tom

GREAT!!!

Works PERFECTLY!!!!

Thank you all!


--
JVLennox
------------------------------------------------------------------------
JVLennox's Profile: http://www.excelforum.com/member.php...o&userid=32505
View this thread: http://www.excelforum.com/showthread...hreadid=526143

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
capitalize first letter rodchar Excel Discussion (Misc queries) 14 December 19th 08 01:47 PM
Capitalize only first letter in sentence ChrisHT Excel Worksheet Functions 1 December 2nd 08 09:57 PM
capitalize first letter automatically raft Excel Discussion (Misc queries) 5 May 1st 08 01:10 PM
Capitalize first letter in sentence Lightjag Excel Worksheet Functions 13 January 15th 08 02:25 PM
Capitalize first letter when type a name in each cell. Craig Brody Excel Worksheet Functions 6 December 20th 04 03:21 PM


All times are GMT +1. The time now is 10:03 AM.

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"