+ Reply to Thread
Results 1 to 4 of 4

Thread: changing to upper case

  1. #1
    Registered User
    Join Date
    11-15-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    31

    changing to upper case

    Hi,

    First of all thanks to all the forum gurus, my programming skills in excel vba has undergone a dramatic improvement. But there the odd glitches and roadblocks that I keep hitting. Look forward to more interaction with the gurus to help me move to the next level.

    I have created a form in which I want the contents of cell S9 to be displayed in upper case. I have written the following code

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("S9")) Is Nothing Then Exit Sub
        Application.EnableEvents = False
        Target = UCase(Target)
        Application.EnableEvents = True
    End Sub
    The code is embedded in the sheet code. This works fine until a user presses the DELETE to delete the contents of this cell. When that happens, I get an error message and the code stops working after that. Thereafter it just does not work even if the workbook is closed and reopened.

    Is there a fix to prevent this or have I missed something in the code ? Any help will be greatly appreciated.

    Thanks in advance

    Anand
    Last edited by anandvh; 02-11-2012 at 02:17 PM.

  2. #2
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: changing to upper case

    Maybe this...

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim Rng As Range
        Set Rng = Target.Parent.Range("S9")
        If Target.Count > 1 Then Exit Sub
        If Intersect(Target, Rng) Is Nothing Then Exit Sub
        If Rng.Value = "" Then Exit Sub
        Application.EnableEvents = False
        Target = UCase(Target)
        Application.EnableEvents = True
    End Sub
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  3. #3
    Registered User
    Join Date
    11-15-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: changing to upper case

    Thanks jeffreybrown,

    Your solution worked. The error message does not come up when the cell contents are deleted. Many thanks for your contribution.

    Anand

  4. #4
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: changing to upper case

    You're welcome Anand, thanks for the feedback and glad it worked for you
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0