+ Reply to Thread
Results 1 to 12 of 12

Excel Macro to change case. Working but not perfect.

  1. #1
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Cool Excel Macro to change case. Working but not perfect.

    I am creating a Macro to change text to Upper Case, then if you run the macro again to Lower Case, then if you run the macro again to Title Case. These functions does not exist in the Excel 2003 interface. So I am making a Macro that eventually I want to turn into a button and after that a plug-in but I'll deal with that when I get there. The idea is to change case of text easily and it be so simple that my not tech savvy co-workers can use it too.

    The below macro works just fine EXCEPT when you don't have more than one cell selected. When you run the macro with only one cell selected, the macro turns the whole worksheet to Upper Case! How do I fix that?

    Please Login or Register  to view this content.
    Last edited by irockyoursocks; 04-14-2011 at 12:47 PM. Reason: inserting code tags

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,255

    Re: Excel Macro to change case. Working but not perfect.

    Hi and welcome to the forum.

    When you post you need to surround your code using code tags to make it easier for everyone to read. Have a look at the forum rules to see how.

    When you're using SpecialCells you have to be careful about a couple of things:
    (1) How many cells the parent range has; and
    (2) [Pre Excel 2010] How many non-contiguous cells it might have to return.

    These items and the results are documented in post #2 here.

    Using your current methodology as a basis, what you'll need to do is check if Selection is only one cell and, if it is, you don't use SpecialCells - you just check whether or not it contains a constant string.

    Overall, I think you end up with something like this:
    Please Login or Register  to view this content.
    Last edited by Colin Legg; 04-13-2011 at 04:29 PM.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Re: Excel Macro to change case. Working but not perfect.

    Colin Legg, you are awesome!

    That code works flawlessly! Even when selecting non-contiguous cells, singles cells or a contiguous group of cells.

    This is so awesome. The next step for me is to make this into a plug -in for Excel 2003 so I don't have to open the excel file every time I use the macro. Any advice on this? I have never made a plug-in.

    Thanks for your grand help,
    Darryl

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,255

    Re: Excel Macro to change case. Working but not perfect.

    Hi,
    The next step for me is to make this into a plug -in for Excel 2003 so I don't have to open the excel file every time I use the macro. Any advice on this? I have never made a plug-in.
    If this was just for your own use then you could put the code in your Personal.xls, attach it to a commandbarbutton and be done: quite straightforward.

    However, in your first post you mentioned that you want your colleagues to be able to use it too. Rather than having everyone set up their own personal.xls, you're probably going to want to create an xla add-in. This is a little bit tricky - particularly when it comes to updating - so will be a learning curve for you.

    As a starting point, have a read though these articles:

    http://www.ozgrid.com/VBA/excel-add-in-create.htm
    If you all have a common server then you'll probably look to save a copy of the add-in on it and then everyone can reference the one file. Provided there isn't a copy on each person's C:\, if you update the network stored add-in then everyone will automatically get the update when they next re-open Excel.

    http://www.excelguru.ca/node/45

  5. #5
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Unhappy Deploy Add In macro not working.

    Quote Originally Posted by Colin Legg View Post
    I am currently trying to get the Deploy Add In code to work. but for some reason the code catches an Error 53 File not found at the setAttribute to normal line(SetAttr strAddinPublicPath & .Name, vbNormal).

    I tried placing this macro in the development excel sheet and in it's own excel sheet too, neither worked. Any help please.

    Darryl

    Please Login or Register  to view this content.
    Last edited by irockyoursocks; 04-19-2011 at 12:45 PM. Reason: change of title

  6. #6
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Re: Deploy Add In macro not working.

    I continue the Add-In conversation here in this Thread:
    http://www.excelforum.com/excel-prog...rror-53-a.html

  7. #7
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Change Case Macro. Error when selecting a merged cell.

    Okay so I ran into a new problem with the Change Case Macro.

    When I have a merged cell highlighted, my above posted change case macro changes the case of the ENTIRE worksheet! This is the same problem I had with the SpecialCells variable before when Colin Legg helped me(as you can read above).

    I don't know how to fix this. And am wondering if it would be better to not use the SpecialCells variable. What do you guys think?

    Darryl

  8. #8
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Talking Excel change case button FINISHED! Have a copy

    I DID IT!!!

    I finally finished the Change Case button. I did away with that DANG SpecialCells variable.
    And I made the counter reset every time you change cell selection, so it's more consistent.
    It's awesome.

    Enjoy
    Please Login or Register  to view this content.

    I am very pleased with what I have made. Please take and use my Add-In. Tell me what you think. And if there are any bugs, let me know.

    And if you like it, comment! So I (and maybe Microsoft) know how many people really like this feature.

    Big thanks to Colin Legg for his help on this project. I feel awesome that I did this, but it wouldn't have been finished if he didn't help me. Thanks Collin!


    Darryl

  9. #9
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Question Change Case Macro. Can I make code faster?

    Okay so I need to make my macro faster. I let my friend use my macro and immediately she used it on two whole columns of data! I only use it on like 20 cells at a time. And when she did that, the macro took a long time. Like 30 seconds. It's always instant for me.

    I am at a crossroads. Should I redefine the selection to something smaller, so the macro isn't processing 65,000 rows of data for nothing?
    Or should I add some code that only applies the changing of the case to the cells that have something?

    Which way is faster?

  10. #10
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Re: Change Case Macro. Can I make code faster?

    Let me just add that I think part of that 30 second lag that my friend experienced was probably due to her crappy slow computer on which she had a ton of programs open.

    But with that said, I'd still like to make my macro seem as instantaneous as possible. Even if selecting whole columns.

  11. #11
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,255

    Re: Excel Macro to change case. Working but not perfect.

    Hi Darryl,

    See if this improves it:
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-13-2011
    Location
    Irvine, CA
    MS-Off Ver
    XP, Excel 2003
    Posts
    14

    Re: Excel Macro to change case. Working but not perfect.

    I just did some initial testing and my macro took 36 seconds to process one column.
    Collin's macro was instantaneous.

    Dang that guy is awesome!

    Thanks Collin

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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