Excel 2002/2003 macros in Excel 2007/2010

GenAMES

New Member
Joined
Aug 1, 2010
Messages
3
Because I'm lazy & want consistency in data input, I wrote the following macro to convert text to upper case in three cells on a worksheet:

Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Value <> "" And Target = [b5] Then
Target.Value = UCase(Target.Value)
End If
If Target.Value <> "" And Target = [b6] Then
Target.Value = UCase(Target.Value)
End If
If Target.Value <> "" And Target = [b7] Then
Target.Value = UCase(Target.Value)
End If
End Sub

it might be a bit clumsy but it worked without any errors.

However, I've been migrated to Excel2010 and now the macro appears to get into a loop, asks me to "End" or "Debug" the macro & my only recourse is to save the spreadsheet, shut excel down through Task Manager and re-open Excel.

Does anyone have any clues/suggestions, please?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
What line does debugger highlight? To see this, press Debug.
 
Upvote 0
Try

Code:
Sub Worksheet_Change(ByVal Target As Excel.Range)
    [COLOR=blue]Application.EnableEvents = False
[/COLOR]    If Target.Value <> "" And Target = [b5] Then
        Target.Value = UCase(Target.Value)
    End If
    If Target.Value <> "" And Target = [b6] Then
        Target.Value = UCase(Target.Value)
    End If
    If Target.Value <> "" And Target = [b7] Then
        Target.Value = UCase(Target.Value)
    End If
    [COLOR=blue]Application.EnableEvents = True
[/COLOR]End Sub

HTH

M.
 
Upvote 0
oops,,

I think you need to use UCase in the IFs like this

Code:
Sub Worksheet_Change(ByVal Target As Excel.Range)
    [COLOR=blue]Application.EnableEvents = False
[/COLOR]    If Target.Value <> "" And UCase(Target) = UCase([b5]) Then
        Target.Value = UCase(Target.Value)
    End If
    If Target.Value <> "" And UCase(Target) = UCase([b6]) Then
        Target.Value = UCase(Target.Value)
    End If
    If Target.Value <> "" And UCase(Target) = UCase([b7]) Then
        Target.Value = UCase(Target.Value)
    End If
    [COLOR=blue]Application.EnableEvents = True
[/COLOR]End Sub

M.
 
Upvote 0
absolutely marvellous. worked a treat. many thanks

You are welcome and tks for the feedback :)

M.
ps: see my last post. I'm not 100% sure about what you want, so, maybe, you have to use UCase, depending on what you need.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top