+ Reply to Thread
Results 1 to 9 of 9

Changing Text Case

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-01-2005
    Location
    Somerset, England
    MS-Off Ver
    Office 2010 Pro
    Posts
    138

    Changing Text Case

    Hi Guys,

    Hopefully someone can help me out with this one please, I have looked through the forum but can't find a relative thread to my question


    I have a sheet covering various ranges A3 down to A37 through to E3 - E37

    All these cells contain text

    What I would like to do is automaically change any entries made in the cells to Proper case.

    Is there anyway of doing this? I have tried the PROPER case function but this does not work for what I need.

    Many thanks

    Paul

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Like so perhaps?
    Sub x()
    Dim rng As Range
    For Each rng In ActiveSheet.UsedRange
        If VarType(rng) = vbString Then rng = WorksheetFunction.Proper(rng)
    Next rng
    End Sub

  3. #3
    Forum Contributor
    Join Date
    12-01-2005
    Location
    Somerset, England
    MS-Off Ver
    Office 2010 Pro
    Posts
    138
    Hi Stephen, Thanks for the reply - I should of said my knowledge of is basic !!

    what do I do with the code ?

    Many thanks

    Paul

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    From your worksheet, press Alt+F11 which opens the VB editor window. Insert menu > Module and paste the code into the white space which appears. To run the macro, from the worksheet Tools > Macro > Macros and select x (change to a more meaningful name).

  5. #5
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454
    Hi,

    Hold down ALT and tap F11

    Do Insert > Module

    paste the code

    use the "X" in the top right to close the VBA editor

    From your workbook go to Tools > Macro > Run Macro

    to activate the code



    If you want the range to update automatically,

    Hold down ALT and tap F11

    Select "ThisWorkbook"

    View > Code

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    If Not Intersect(Target, Range("A3:E37")) Is Nothing Then Target.Value = Application.WorksheetFunction.Proper(Target.Value)
    End Sub

    use the "X" in the top right to close the VBA editor
    Last edited by sweep; 11-05-2008 at 09:02 AM. Reason: Missed the error handling
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  6. #6
    Forum Contributor
    Join Date
    12-01-2005
    Location
    Somerset, England
    MS-Off Ver
    Office 2010 Pro
    Posts
    138
    Many thanks guys - those options both work a treat and I have learnt something new !!

    I appriciate your time in replying

    Best wishes

    Paul

  7. #7
    Forum Contributor
    Join Date
    12-01-2005
    Location
    Somerset, England
    MS-Off Ver
    Office 2010 Pro
    Posts
    138
    Me again - sorry guys just a quick follow on ...

    is there an issue with security settings that stops this code working if I close theworkbook and then re-open it later, as I have tried this and the code stopes working.

    I am using Excel 2007 to design the workbook and saving it as a "Excel 97-2003" so that others can use it.

    Each time I save i then reopen it the code seems to stop even though after going into the Alt- F11 bit the code is still there?

    sorry to be a pain !

    Thanks

+ 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.6.0 RC 1