Pull Characters From Alpanumerics and Right Align

  • I am trying to create a data sheet to simplify the filling of corporate documents on our company computer systems. I have a working system, flawed, but working. What I want is to simplify it and correct some mistakes I made when I first made it. At the moment the priority is the field for our serial numbers. They vary from 1 to 10 digits in length with a alpha-numeric system. Some serial numbers even include hyphens, but the hyphens need to be removed for the forms. My system uses a modified form to allow for hyphens, but my boss wants them removed. ^^'


    I must apologize now, though. My boss knows I'm requesting help here and all, but he said I couldn't put the document up, sorry. :S


    Anyways, the serial number of an item is entered into the data sheet field and my macro breaks down the serial number piece by piece. On the form the there are ten blocks for each digit of the serial number and I have coded the macro to put one digit per box. The trick is that the serial number must be right aligned and any empty fields must stay empty. This is where my request comes into play. I have already programmed the macro to do everything required except remove hyphens. The problem is that it is a REALLY long macro using If Then End statements to to compensate for the varying lengths of a serial number. Is there anyway to simplify this task?



    Oh, I almost forgot, due to the rest of the form the fields the serial number is being put into are merged cells, I hope that doesn't make a difference. :S


    Thank you for simply taking a look at my request! ^^

  • Re: Pull Numbers From Alpanumerics


    If you're on a PC, this should work.

    I'm not entirely sure that "StrReverse" is the proper spelling of the function. If you are on a Mac, an emulator will be needed.

  • Re: Pull Numbers From Alpanumerics


    I don't think I was as clear as I had thought. ^^'


    Attached is a blank copy of what I have, nothing of the form except where the serial number will be going. It is in XLS format for PCs at my work without 2007 on them.


    Basically, the user will enter the serial number into a single cell on the data page. Some serial numbers will be 10 digits long not including hyphens. The ERO page, which is the blank form page, is set-up for only 10 digits in the serial number area. I would shorten it but the form will print onto a pre-made form that is manufactured with only 10 slots. As a result, for the 10 digit long serial numbers, or rather any length, the hyphens must be removed. In addition it must be right justified with the remaining field left empty.


    I've created the really long code from my original post to split up the serial number and insert it into the blocks right justified, but it doesn't compensate for hyphens, and if possible I'd like to shorten it.


    mikerickson
    Thank you for the code snippet, but it didn't work. :S


    Thanks again for simply looking at it. I really appreciate this. ^^

  • Re: Pull Numbers From Alpanumerics


    Remove the hyphens from serial numbers, split the result into individual alphanumeric digits, and paste those digits in the original order while right justified on the ERO page.


    Also, I don't wish to sound rude of anything, but the serial number on the Data page was a demo serial I left there for use by programmers while experimenting with code. The ERO sheet was the exact form we use with everything EXCEPT the serial number location erased. My boss wouldn't let me post it otherwise. Attached to the document is also the macro that mikerickson posted for use.

  • Re: Pull Numbers From Alpanumerics


  • Re: Pull Numbers From Alpanumerics


    If your boss knows you are seeking help why won't they let you post some sample data?


    We don't need to see the 'real' data, just something representative of what you are dealing with.


    It might also help if you were to explain why you need to do this in the first place.


    Why do you need to extract the numbers?


    Oh, and by the way merged cells might actually make a difference - especially since they are evil personified.:yikes:

    Boo!:yikes:

  • Re: Pull Numbers From Alpanumerics


    Thank you, the code worked perfectly to remove the hyphen, but it didn't do anything for placing the serial number into the ERO sheet. :S


    BU4 = T
    CA4 = H
    CG4 = M
    CM4 = 5
    CS4 = 9
    CY4 = 2
    DE4 = 8
    DK4 = 5
    DQ4 = 7
    DW4 = 3


    The problem isn't that I can't split it or right align it, but that the code is much to extensive, it is too difficult to edit should I have to edit it.


    For instance, if the serial number were GS5F-332 it would have to appear as:


    BU4 =
    CA4 =
    CG4 =
    CM4 = G
    CS4 = S
    CY4 = 5
    DE4 = F
    DK4 = 3
    DQ4 = 3
    DW4 = 2


    The issue is with splitting up the serial number into the individual blocks.


    When I defined SerialNo1 as the first letter to goto BU4 in the ERO sheet it will grab the first digit and left align it:


    BU4 = G
    CA4 = S
    CG4 = 5
    CM4 = F
    CS4 = 3
    CY4 = 3
    DE4 = 2
    DK4 =
    DQ4 =
    DW4 =


    If I work backwards, which is what I had originally done, it defines 10 strings for 10 cells and makes the last digit in the serial number the first serial number digit to be entered into the right block, moving left. This resulted in the last digit being copied, the first digit of the serial number, to repeat in every remaining block:


    BU4 = G
    CA4 = G
    CG4 = G
    CM4 = G
    CS4 = S
    CY4 = 5
    DE4 = F
    DK4 = 3
    DQ4 = 3
    DW4 = 2


    Is there a way to cut down the original code I put in my first post to make it appear like:


    Data Page


    AA4 = GS5F-332


    ERO Page


    BU4 =
    CA4 =
    CG4 =
    CM4 = G
    CS4 = S
    CY4 = 5
    DE4 = F
    DK4 = 3
    DQ4 = 3
    DW4 = 2


    That was the main thing I wished to solve, was the extensive amount of editing required to change a variable, whether to add a digit, remove a digit, or simply change how it shows up. I'm sorry for making it seem so...weird. Please, feel free to charge an extra question or two for the trouble. I got extra anticipating problems from my end. ^^'


    norie
    Well, my boss is technically the president of the United States. The US Military operates like that. ^^'


    Anyways, to answer your question, the actual form is classified, which is why I was required to remove everything from it. I'm sorry for the trouble it's caused, but I have no option in the matter.


    Also, for your question about extracting the serial number, I'm attempting to create a data sheet that will completely fill in the document as it is suppose to be filled in. On the actual document there are certain things that must be broken up by blocks, says someone 50 years ago when the form was first created. This is meant as a way for personnel that are not familar with filling out these forms to do so easily by simply providing the required information to one page and having everything else done for them.


    Lastly, the merged cells is also a problem I've had no choice but to deal with. The document was designed to print onto premade forms. On these forms the blocks overlap, requiring in an Excel document to use merged cells.




    Again, I must apologize for all the trouble this has caused, and any further assistance is greatly appreciated. ^^

  • Re: Pull Numbers From Alpanumerics



    Call the macro with the string that you want to display, like I did in the Driver macro -

    Code
    Call out2Cell("THM-285123")


    By the way, I dont think you need to use ".FormulaR1C1" in the range statement. Use ".value" instead - it will probably be more appropriate. I left in ".FormulaR1C1" because I dont have full exposure to your sheet (no worries) ;)


    Quote


    Well, my boss is technically the president of the United States. The US Military operates like that. ^^'


    Classic ::D


    HTH
    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Pull Characters From Alpanumerics and Right Align


  • Re: Pull Characters From Alpanumerics and Right Align


    nice one dave, I keep forgetting that "Choose"...

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Pull Characters From Alpanumerics and Right Align


    For this I'm uploading a fairly complete copy of the form. I removed certain fields due to...issues.


    Anyways, with the exception of the fields I had to remove that is the actual document I've been working on with ALL the code and the different versions of them that I've used. I did edit the code provided to use a cell for dynamic serial numbers instead of the static text of the original codes provided.


    Other than that, I don't recall editing it, and due to my current situation I can't compare the code from here to that of the document. ^^'


    With the current code set as SerialNo I get a syntax error. :S

  • Re: Pull Characters From Alpanumerics and Right Align


  • Re: Pull Characters From Alpanumerics and Right Align


    I can't believe I didn't get this before! You guys are all amazing, I just didn't put things together.


    Although none of the code snippets did EXACTLY what I wanted, every part I needed was in a version of the code!


    After have brooded over it for a few days I figured it out, thanks heavily to everyone for helping.



    You guys are absolutely amazing and I'm sorry for all the trouble I caused. ^^'


    I must ask one more thing though, could someone please remove that attachment from my last post, I'm afraid I don't know how. :S

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!