+ Reply to Thread
Results 1 to 10 of 10

Help with VBA for propercase

  1. #1
    Registered User
    Join Date
    02-26-2011
    Location
    Watertown, CT
    MS-Off Ver
    Excel 2003
    Posts
    12

    Help with VBA for propercase

    I have an excel sheet where I want all cells to have propercase. (First letter of each word is capital) I've seen several macros that do this but they all give me errors. Also, is it possible to save the macro to the personal.xlsb file so I could run it on any sheet?

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Help with VBA for propercase

    Hi boolean and welcome to the forum.

    There isn't a Proper function living in VBA so you need to use the Excel function like this.

    If A1 = Bob and mary went to the store.

    Using Excel Proper (A1) gives

    Bob And Mary Went To The Store.

    You can try to write one like at http://www.mvps.org/dmcritchie/excel/proper.htm

    But it is a lot easier to simply call the worksheet function from Excel into your VBA code like

    WorksheetFunction.Proper(Range("A1")) and it will return what you want.

    I hope this helps.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with VBA for propercase

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Help with VBA for propercase

    I stand corrected! shg is the master!!

    There is a proper case in VBA.

    see all of them at http://msdn.microsoft.com/en-us/libr...73(VS.60).aspx

  5. #5
    Registered User
    Join Date
    02-26-2011
    Location
    Watertown, CT
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Help with VBA for propercase

    Here we go!

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 02-26-2011 at 07:50 PM. Reason: Added Code Tags

  6. #6
    Registered User
    Join Date
    02-26-2011
    Location
    Watertown, CT
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Help with VBA for propercase

    Please Login or Register  to view this content.
    This macro works when I set the range to A1:A90000 but it freezes up when I select the entire column A:A. I found a couple workarounds that use a large amount of VBA just to return the last cell in a column. is there a better way to select all used cells in specific columns?

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Help with VBA for propercase

    Hi,
    Use code like:
    Please Login or Register  to view this content.
    Then define your range as
    Please Login or Register  to view this content.
    see if that works for youj.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with VBA for propercase

    One way:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-26-2011
    Location
    Watertown, CT
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Help with VBA for propercase

    Quote Originally Posted by MarvinP View Post
    Hi,
    Use code like:
    Please Login or Register  to view this content.
    Then define your range as
    Please Login or Register  to view this content.
    see if that works for youj.
    Thanks a ton, that works for a single column.

    How could I select multiple columns with this. I think I could reuse the & LastRow because column A will always have as many entries as all the other cells.
    Please Login or Register  to view this content.
    I tried this but it gave a syntax error.

  10. #10
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Help with VBA for propercase

    Look at shg's UsedRange above.
    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    or search the net for VBA UsedRange for more examples.

+ 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