Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default One single character to upper case

I'm trying to do a simple macro to change the third character in a
selected cell to upper case, if the first two characters are "Mc".
It's for an address list where the names go Mcintosh, Mcardle, etc and
really need to be McIntosh, McArdle, with the third character
uppercase. I tried the macro below but it doesn't work. Am I using
UCase in the wrong way, or the MID function?

Sub McName_Adjustment()
Dim cell As Range
For Each cell In Selection.Cells
a = cell.Value
If Left(a, 2) = "Mc" Then
UCase (Mid(a, 3, 1))
End If
Next
End Sub

Thanks for any advice anyone can give.
Steve Wylie
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default One single character to upper case

Try it this way (using Mid in both it Statement and its Function form)...

Sub McName_Adjustment()
Dim cell As Range
For Each cell In Selection.Cells
a = cell.Value
If Left(a, 2) = "Mc" Then
Mid(a, 3, 1) = UCase(Mid(a, 3, 1))
End If
Next
End Sub

--
Rick (MVP - Excel)


wrote in message
...
I'm trying to do a simple macro to change the third character in a
selected cell to upper case, if the first two characters are "Mc".
It's for an address list where the names go Mcintosh, Mcardle, etc and
really need to be McIntosh, McArdle, with the third character
uppercase. I tried the macro below but it doesn't work. Am I using
UCase in the wrong way, or the MID function?

Sub McName_Adjustment()
Dim cell As Range
For Each cell In Selection.Cells
a = cell.Value
If Left(a, 2) = "Mc" Then
UCase (Mid(a, 3, 1))
End If
Next
End Sub

Thanks for any advice anyone can give.
Steve Wylie


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default One single character to upper case

Of course, you have to assign it back to the cell. Add this just before the
End Sub statement...

cell.Value = a

By the way, the Mid Statement requires the first argument to be a variable,
so you can't use cell.Value in it directly.
--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Try it this way (using Mid in both it Statement and its Function form)...

Sub McName_Adjustment()
Dim cell As Range
For Each cell In Selection.Cells
a = cell.Value
If Left(a, 2) = "Mc" Then
Mid(a, 3, 1) = UCase(Mid(a, 3, 1))
End If
Next
End Sub

--
Rick (MVP - Excel)


wrote in message
...
I'm trying to do a simple macro to change the third character in a
selected cell to upper case, if the first two characters are "Mc".
It's for an address list where the names go Mcintosh, Mcardle, etc and
really need to be McIntosh, McArdle, with the third character
uppercase. I tried the macro below but it doesn't work. Am I using
UCase in the wrong way, or the MID function?

Sub McName_Adjustment()
Dim cell As Range
For Each cell In Selection.Cells
a = cell.Value
If Left(a, 2) = "Mc" Then
UCase (Mid(a, 3, 1))
End If
Next
End Sub

Thanks for any advice anyone can give.
Steve Wylie



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default One single character to upper case

You could try the enclosed in excell
=IF(LEFT(B6,2)="MC","Mc"&(UPPER(MID(B6,3,1)))&MID( B6,4,30),IF(LEFT(B6,3)="MaC","Mac"&(UPPER(MID(B6,4 ,1)))&MID(B6,5,30),(B6)))

where the original format name is in column B-
Not in a macro but does the job
--
Thanks for your help


" wrote:

I'm trying to do a simple macro to change the third character in a
selected cell to upper case, if the first two characters are "Mc".
It's for an address list where the names go Mcintosh, Mcardle, etc and
really need to be McIntosh, McArdle, with the third character
uppercase. I tried the macro below but it doesn't work. Am I using
UCase in the wrong way, or the MID function?

Sub McName_Adjustment()
Dim cell As Range
For Each cell In Selection.Cells
a = cell.Value
If Left(a, 2) = "Mc" Then
UCase (Mid(a, 3, 1))
End If
Next
End Sub

Thanks for any advice anyone can give.
Steve Wylie

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default One single character to upper case

Thanks, Rick. Of course, I should have realised the amended text
would need putting back into the cell!

And thanks too, David, but I really did need this in a macro rather
than a formula.

Steve


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default One single character to upper case

Hi all!

You can use the power of Excel within your code.
For example:
If the range with the names contains only a single column,
try the macro below.

'-----------------8<----------------------------

Private Declare Function GetTickCount Lib "kernel32" () As Long

Sub Quick_McName_Adjustment()
Dim lngStart As Long
Dim strRef As String

lngStart = GetTickCount
Application.ScreenUpdating = False
strRef = Selection.Range("A1").Address(False, False)
With Selection.Cells.Offset(, 1)
.Insert xlToRight
.FormulaLocal = "=IF(LEFT(" & strRef & ";2)=""Mc"";" _
& "SUBSTITUTE(" & strRef & ";RIGHT(" & strRef & ";" _
& "LEN(" & strRef & ")-2);PROPER(RIGHT(" & strRef & ";" _
& "LEN(" & strRef & ")-2)));" & strRef & ")"
.Copy
Selection.PasteSpecial (xlPasteValues)
.Delete xlToLeft
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Debug.Print "Quick_McName_Adjustment: " & GetTickCount - lngStart & "
msec"
End Sub

'-----------------8<----------------------------

Enable the Immediate window to see the results.
In my system it needs 62 msec for the range "A1:A10000".

Sorry for my English.
I do not speak english very well. :-(

John

Ο χρήστης " *γγραψε:

Thanks, Rick. Of course, I should have realised the amended text
would need putting back into the cell!

And thanks too, David, but I really did need this in a macro rather
than a formula.

Steve

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default One single character to upper case

Correction!

My previous macro (Quick_McName_Adjustment) contains a problem.
Use the macro above :

'-----------------8<----------------------------

Private Declare Function GetTickCount Lib "kernel32" () As Long

Sub Quick_McName_Adjustment2()
Dim lngStart As Long
Dim strRef As String

lngStart = GetTickCount
Application.ScreenUpdating = False
strRef = Selection.Range("A1").Address(False, False)
Selection.Cells.Offset(, 1).Insert xlToRight

With Selection.Cells.Offset(, 1)
..FormulaLocal = "=IF(LEFT(" & strRef & ";2)=""Mc"";" _
& "SUBSTITUTE(" & strRef & ";RIGHT(" & strRef & ";" _
& "LEN(" & strRef & ")-2);PROPER(RIGHT(" & strRef & ";" _
& "LEN(" & strRef & ")-2)));" & strRef & ")"
..Copy
Selection.PasteSpecial (xlPasteValues)
..Delete xlToLeft
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Debug.Print "Quick_McName_Adjustment2: " _
& GetTickCount - lngStart & " msec"
End Sub

'-----------------8<----------------------------

Sorry for my carelessness.
--
John
--


Ο χρήστης "John_John" *γγραψε:

Hi all!

You can use the power of Excel within your code.
For example:
If the range with the names contains only a single column,
try the macro below.

'-----------------8<----------------------------

Private Declare Function GetTickCount Lib "kernel32" () As Long

Sub Quick_McName_Adjustment()
Dim lngStart As Long
Dim strRef As String

lngStart = GetTickCount
Application.ScreenUpdating = False
strRef = Selection.Range("A1").Address(False, False)
With Selection.Cells.Offset(, 1)
.Insert xlToRight
.FormulaLocal = "=IF(LEFT(" & strRef & ";2)=""Mc"";" _
& "SUBSTITUTE(" & strRef & ";RIGHT(" & strRef & ";" _
& "LEN(" & strRef & ")-2);PROPER(RIGHT(" & strRef & ";" _
& "LEN(" & strRef & ")-2)));" & strRef & ")"
.Copy
Selection.PasteSpecial (xlPasteValues)
.Delete xlToLeft
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Debug.Print "Quick_McName_Adjustment: " & GetTickCount - lngStart & "
msec"
End Sub

'-----------------8<----------------------------

Enable the Immediate window to see the results.
In my system it needs 62 msec for the range "A1:A10000".

Sorry for my English.
I do not speak english very well. :-(

John

Ο χρήστης " *γγραψε:

Thanks, Rick. Of course, I should have realised the amended text
would need putting back into the cell!

And thanks too, David, but I really did need this in a macro rather
than a formula.

Steve

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default One single character to upper case

Thanks, John.

Steve
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
Need character for custom format to force upper case! Andrew C[_2_] Excel Discussion (Misc queries) 2 April 1st 09 06:03 AM
Changing file in all upper case to upper and lower case Sagit Excel Discussion (Misc queries) 15 May 30th 07 06:08 AM
Case sensitive and single character in cell praveen_khm[_22_] Excel Programming 0 February 7th 06 02:21 PM
Determine whether a character is Upper or Lower case [email protected] Excel Programming 2 December 2nd 05 09:44 PM
Changing single column default to Upper case Graham Excel Discussion (Misc queries) 4 September 27th 05 05:17 PM


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