+ Reply to Thread
Results 1 to 13 of 13

Write macros to automatically Sort AND Convert Letters to Numbers

  1. #1
    Registered User
    Join Date
    11-16-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    42

    Write macros to automatically Sort AND Convert Letters to Numbers

    Hello, i am VERY new to writing vb in excel but have experience with writing in access so im familiar with the coding.

    I want to write 1 macros that accomplishes the things below, this can either happen on automatic update of the spreadsheet or maybe a button insert and changes on click, whichever is easier. Thanks for the help!!!


    1)I have an ID column (A1) called AMR AIS. I want to convert anything in this column that begins with a letter to a numeric value.
    A=1; B=2, C=4, D=5, E=7, F=9 <--These are the only possible conversions. If it begins with a number, then dont do any conversions. Also, if it begins with an "x" or a "y" or "null" it should be deleted.
    2) After the above conversion, I need to add "00" to the front of every value in the same column.
    3) After step 2, last thing is to sort this column from lowest to highest


    If anyone can please help me write a macros for these steps, if greatly appreciate it! Thanks!!

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    taimysho0,

    Something like this should accomplish what you're looking for:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    11-16-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    hello, thanks so much! however, im confused to where i should be putting this code. does it go straight into the worksheet, or do i create as a module or? thanks!!

  4. #4
    Registered User
    Join Date
    11-16-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    hello, i ran it as a macros, and it errored out, it also did some weird sorting of the data as you can see in the picture attached. I dont want it filtered, just sorted. thanks!!

    error1.jpg

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    taimysho0,

    Attached is an example workbook based on the criteria described. It contains the proposed macro in a standard module. I am able to run it with no errors. The filter is to delete all rows that contained "x", "y", or "null". If your data is different or if you continue to get an error, please upload a sample workbook with mock data that is experiencing the problem so that I can troubleshoot the code.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-16-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    hello, thanks for all the help. i downlaoded your copy and it does the conversion but it came up with the same erro message "code execution has been interuppted" i attached a picture of where the code stopped in attachment. im also attaching my copy of the spreadsheet. I noticed on yours, the letters were converted but on mine, they still did not convert. Thanks!!

    error2.jpg
    testdata2.xls

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    taimysho0,

    Updated code. The autofilter is only there to delete rows of cells that contained "x", "y", or "null". I have changed it from a filter to a .Find loop to avoid errors. It ran successfully on your test workbook. Let me know if this works for you:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-16-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    Thanks so much!! The only thing is, it deletes my row formula in my row count column. Is there a way to avoid this?

  9. #9
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    To just clear the cell contents instead of deleting the entire row, change this line:
    Please Login or Register  to view this content.

    To be this instead:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-16-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    hrmm, i cant seem to get it to work right, sorry to keep asking for more but is there a way to code a column append to the macros? for example, can i add some code that will append a column called "Row Count" with the formula =row()-1 every time the macros is ran? THANKS!

  11. #11
    Registered User
    Join Date
    11-16-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    or if this is easier, if theres a way to activate the formula in my selected cell to all the cells below it, within the macros. for example if my formula is in cell H1, when the macros run it also assigns the formula in that cell to all the cells beneath it?

  12. #12
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    untested, but you could try adding this line to the end of the macro:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-16-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Write macros to automatically Sort AND Convert Letters to Numbers

    awesome, thanks so much!

+ 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