Consulting

Results 1 to 10 of 10

Thread: Solved: Upper/Lower Case

  1. #1
    VBAX Tutor GaryB's Avatar
    Joined
    Jun 2004
    Location
    Stockton, California
    Posts
    270
    Location

    Solved: Upper/Lower Case

    Hi,

    I have an excel file that I imported from one of our databases and everything in it is capitalized. I could export it as a comma delimited file into a word processing program to make it upper and lower case type , but I was wondering if there is any way, in Excel, to do this. As usual any help is always appreciated.

    Thanks,

    Gary

  2. #2
    Hi Gary

    Here's the code:
    [vba]Sub test()
    Dim c As Range
    For Each c In ActiveSheet.Range(Cells(1, 1), Cells(1, 1).SpecialCells(xlLastCell)).Cells
    If Left(c.Formula, 1) <> "=" Then c.Value = LCase(c.Value)
    Next c
    End Sub[/vba] And here's what it does:
    Takes all cells in the used range of ActiveSheet, and changes the cell values to lower case, except when there is a formula in the cell.
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  3. #3
    VBAX Tutor GaryB's Avatar
    Joined
    Jun 2004
    Location
    Stockton, California
    Posts
    270
    Location
    HI Jimmy,

    I see what this does and it's great but I am looking for some that will leave the first letter of each word Capatalized os end up upper and lower case type.

    thanks for the help

    Gary

  4. #4
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    if your data is in A1, place this in B1 and copy down.

    [VBA]=proper(a1)[/VBA]

  5. #5
    In this case the code changes to
    [vba] Dim c As Range
    For Each c In ActiveSheet.Range(Cells(1, 1), Cells(1, 1).SpecialCells(xlLastCell)).Cells
    If Left(c.Formula, 1) <> "=" Then c.Value = Application.WorksheetFunction.Proper(c.Value)
    Next c[/vba]
    Thanks to austenr for the tip
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't understand why people test cell for formula as starting with = when there is a built-in method

    [vba]

    If c.HasFormula Then ...
    [/vba]

  7. #7
    Quote Originally Posted by xld
    I don't understand why people test cell for formula as starting with = when there is a built-in method

    [vba]

    If c.HasFormula Then ...
    [/vba]

    That's probably because people don't know about the built-in method...
    I was ignorant, too, but not anymore I mean, not that ignorant.
    Thanks for the tip
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by JimmyTheHand
    That's probably because people don't know about the built-in method...
    I was ignorant, too, but not anymore
    Spreading the word ...

  9. #9
    VBAX Tutor GaryB's Avatar
    Joined
    Jun 2004
    Location
    Stockton, California
    Posts
    270
    Location
    Thanks to everyone for the help. The code did what I needed it to do.

    Thanks again,
    Gary

  10. #10
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Also, the special cells last cell can be thrown off and is not really reliable. Either use the Cells.Find("*") or the Rows.Count method. Or another way to not loop through all cells is to use the special cells formulas. However you would need to error trap it as if there were no formulas it would error out that line of code. Should prove faster.

    HTH

Posting Permissions

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