View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default 3 letter capitalisation

How about:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myConversion As Long
Dim sStr As String

On Error GoTo ErrHandler

If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("c:c")) Is Nothing Then Exit Sub

Select Case Len(Target.Value)
Case Is = 3: myConversion = vbUpperCase
Case Else: myConversion = vbProperCase
End Select

sStr = StrConv(Target.Value, myConversion)

If sStr < Target.Value Then
Application.EnableEvents = False
Target.Value = sStr
End If

ErrHandler:
Application.EnableEvents = True
End Sub


Voodoodan wrote:

Hiya,

I've modified a bit of code, below, so that if someone types anything
into cell C25, then it capitalises the first letter.

Is there any way of modifying it a little bit more so that, as well as
the above, if someone types in a 3-letter word then it capitalises all
three letters?

So, if I enter 'daniel', it returns 'Daniel'. If I enter 'dan' it
returns 'DAN'.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

On Error GoTo ErrHandler
If Target.Count = 1 And Target.Column = 3 Then
Application.EnableEvents = False
sStr = Target.Value
Target.Value = UCase(Left(sStr, 1)) & LCase( _
Mid(sStr, 2))
End If
ErrHandler:
Application.EnableEvents = True
End Sub

Many thanks,
Dan.

--
Voodoodan
------------------------------------------------------------------------
Voodoodan's Profile: http://www.excelforum.com/member.php...nfo&userid=597
View this thread: http://www.excelforum.com/showthread...hreadid=505301


--

Dave Peterson