I want to run a code, so that all the cells of the worksheet can be effected
to change the first letter of the cell into capital.
I was able to know with the web helps examples, by that I can do it manually
with the cell reference one by one. the formula is as below :
=CONCATENATE(UPPER(LEFT(A1,1)),LOWER(RIGHT(A1,LEN(A1)-1)))
But I want to run in a code for the complete sheet, so once I run the code
and it can be effective for all the sheet
pls. advice
Irshad
For Each cell In ActiveSheet.UsedRange
If cell.Value <> "" Then
cell.Value = UCase(Left(cell.Value, 1)) & Right(cell.Value,
Len(cell.Value) - 1)
End If
Next cell
--
__________________________________
HTH
Bob
"Irshad Alam" <Irsha...@discussions.microsoft.com> wrote in message
news:398F6207-6B88-4BAF...@microsoft.com...
cell.Value = WorksheetFunction.Proper(cell.Value)
Stefi
„Bob Phillips” ezt írta:
--
__________________________________
HTH
Bob
"Stefi" <St...@discussions.microsoft.com> wrote in message
news:5ADB9D64-44A5-49A9...@microsoft.com...
Please explain disadvantages of calling worksheet functions when also other
means are available.
What is the difference between the two ways of changing the first letter to
capitals?
Thanks,
Not sure in what way the Proper function doesn't achieve what the OP
requests.
--
Regards
Roger Govier
"Bob Phillips" <Bob...@somewhere.com> wrote in message
news:uCN#NtbDJH...@TK2MSFTNGP05.phx.gbl...
But if the user wants just the first letter in the cell uppercase, then maybe
not.
But I'd have used:
cell.Value = UCase(Left(cell.Value, 1)) _
& lcase(Right(cell.Value, Len(cell.Value) - 1))
or
cell.Value = UCase(Left(cell.Value, 1)) & lcase(mid(cell.Value, 2)
to match the sample worksheet function the OP gave.
--
Dave Peterson
And there's a difference if there are are multiple words in the cell.
And as well as ucase() and lcase(), VBA has its own strconv(), too.
--
Dave Peterson
--JP
> > >> "Irshad Alam" <IrshadA...@discussions.microsoft.com> wrote in message
--
__________________________________
HTH
Bob
"Roger Govier" <roger@technology4unospamdotcodotuk> wrote in message
news:7DA4D44D-ACF6-48B6...@microsoft.com...
The OP also said that they wanted to change the first letter of the cell,
not the first letter of every word in the cell as Proper would do.
--
__________________________________
HTH
Bob
"Stefi" <St...@discussions.microsoft.com> wrote in message
news:5813079D-9FEC-48E6...@microsoft.com...
--
Regards
Roger Govier
"Bob Phillips" <Bob...@somewhere.com> wrote in message
news:e2rBRccD...@TK2MSFTNGP04.phx.gbl...
The code you advised was :
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Value <> "" Then
cell.Value = UCase(Left(cell.Value, 1)) & Right(cell.Value,
Len(cell.Value) - 1)
End If
Next cell
Please note that my requirement is to make only the first word first letter
capital only
Exactly the result which this formula gives
=CONCATENATE(UPPER(LEFT(A1,1)),LOWER(RIGHT(A1,LEN(A1)-1)))
My requirement is exactly the result of the above formula BUt for all the
sheet.
Regards
Irshad
--
__________________________________
HTH
Bob
"Irshad Alam" <Irsha...@discussions.microsoft.com> wrote in message
news:CAC1A9F2-CAEC-4B9C...@microsoft.com...
--
Dave Peterson
I have re-checked my above posting works fine, the same type in Microsoft
word if you start a sentence by typing small letters, when you move to next
line pressing enter, it automatically makes the first letter of the sentence
capital.
Exactly this is my requirement which I am able to solve by the indiviual
cell by this formula:
=CONCATENATE(UPPER(LEFT(A1,1)),LOWER(RIGHT(A1,LEN(A1)-1)))
But I want a vba, so that once I run, it will work for the complete
selection for making all the cells first letter (of first word) into capital.
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10" 'adjust to suit
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
For Each cell In Target
If cell.Value <> "" Then
cell.Value = UCase(Left(cell.Value, 1)) & Right(cell.Value, _
Len(cell.Value) - 1)
End If
Next cell
End If
ws_exit:
Application.EnableEvents = True
End Sub
This is sheet event code. Right-click on the sheet tab and "View Code"
Copy/paste into that sheet module. Edit to suit the range.
Alt + q to return to the Excel window.
Gord Dibben MS Excel MVP