+ Reply to Thread
Results 1 to 5 of 5

VBA Extract Numbers And Insert Words

  1. #1
    Registered User
    Join Date
    07-27-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    VBA Extract Numbers And Insert Words

    Hi All,

    Hopefully someone will be able to help me with this.

    I’m slowly teaching myself some VBA but it’s an uphill struggle at the moment!!!

    I have attached a copy of the spreadsheet im working on, What I need to do is:

    In column N insert the word ‘Class’ in front of the numbers in the column and ‘:’ after the number followed by a hard return, so N2 goes from this –

    14 Precious metals and their allies and goods in precious metals or coated therewith, not included in other classes; jewellery (imitation jewellery of precious metals and stones); precious metals; cuff links, tie pins, horological and chronometric instruments.

    To this:

    Class 14:
    Precious metals and their allies and goods in precious metals or coated therewith, not included in other classes; jewellery (imitation jewellery of precious metals and stones); precious metals; cuff links, tie pins, horological and chronometric instruments.


    The way i was doing this is by using find and replace for all the various different numbers, most of the numbers seem to follow with 3 or 4 spaces so i was quite easily able to isolate them and change them all except that I couldn’t manage to get the hard return to fall in the fight place always (see further below)

    It starts like: (Cell N94)

    9 Swimming goggles; sunglasses; spectacles; eyewear; life-saving and teaching apparatus and instruments; swimmers and divers earplugs; nose clips; bathing floats; life buoys; life belts; breathing apparatus for underwater swimming. 18 Leather and imitations of leather, and goods made of these materials not included in other classes; animal skins, hides; trunks and travelling bags; umbrellas, parasols and walking sticks; bags; satchels; holdalls; wallets; purses; trunks; portfolios; attaché cases; briefcases; backpacks; gym bags; sports bags; tote bags; suitcases. 25 Clothing, footwear, headgear, swimwear.

    I can get it to this by using the find and replace feature:

    Class 9:
    Swimming goggles; sunglasses; spectacles; eyewear; life-saving and teaching apparatus and instruments; swimmers and divers earplugs; nose clips; bathing floats; life buoys; life belts; breathing apparatus for underwater swimming. Class 18:
    Leather and imitations of leather, and goods made of these materials not included in other classes; animal skins, hides; trunks and travelling bags; umbrellas, parasols and walking sticks; bags; satchels; holdalls; wallets; purses; trunks; portfolios; attaché cases; briefcases; backpacks; gym bags; sports bags; tote bags; suitcases. Class 25:
    Clothing, footwear, headgear, swimwear.


    But i need it like this:

    Class 9:
    Swimming goggles; sunglasses; spectacles; eyewear; life-saving and teaching apparatus and instruments; swimmers and divers earplugs; nose clips; bathing floats; life buoys; life belts; breathing apparatus for underwater swimming.
    Class 18:
    Leather and imitations of leather, and goods made of these materials not included in other classes; animal skins, hides; trunks and travelling bags; umbrellas, parasols and walking sticks; bags; satchels; holdalls; wallets; purses; trunks; portfolios; attaché cases; briefcases; backpacks; gym bags; sports bags; tote bags; suitcases.
    Class 25:
    Clothing, footwear, headgear, swimwear.


    I have been going through the sheet manually to get it straight at the moment which is a pain.

    There is also a slight problem in that some of the cells already contain the wording ‘Local Class #’ (see cell N1515), these need to stay as they are. (I’m not sure if this is a problem or not)

    The next thing to do is i need to pull through the numbers from the Colum N into Columns I-M in numerical order (which they should already be in) ( some more columns need to be added in to accommodate all the numbers that are in column N, i haven’t added them in yet, 8 extra colums should do it). I was using ‘getnumber’ to extract the numbers but it just bunched them together, i was trying to get a space or a delimiter inserted so i could do text to columns’ and then pull them across but that’s where i got stuck!!

    I need to apply this to quite a few sheets which is why I’m asking for help as they are all in the same format and need to have the same thing done to them!!!

    I hope it all makes sense (ignore what is in column O as this is just me playing about)

    Any help you can give me or pointing me in the right direction would be greatly appreciated.

    Many thanks

    Jamie

    Oh, and im using Excel 2010
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    07-27-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: VBA Extract Numbers And Insert Words

    I have just had this from my friend:

    "Getnumbers is a good start.

    I would have a look at split instead of looping through the string for the.

    e.g.
    This will split the cell content into small chunks delimited by the space, not tested but should work:
    Please Login or Register  to view this content.
    You can then repeat the above but use instr in order to find the location of each number.

    e.g.

    instr(split(getnumbers)(i),ctext,1,1)

    this will give you the numeric position of the number from which you can then do some string manipulation.

    newstring = left(oldstring,location_of_number-2) & "class " & mid(oldstring,location_of_number,2) & vcbcrlf & mid(oldstring,location_of_number+2)

    That should hopefully be enough to get you started"

    Im still a bit lost though!!
    Last edited by arlu1201; 04-25-2012 at 06:52 AM. Reason: Code tags.

  3. #3
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544

    Re: VBA Extract Numbers And Insert Words

    For example

    Please Login or Register  to view this content.
    will show "a" and "b" on different lines
    Just keep it simple !


    http://www.excelguide.eu
    In English as well as in Dutch

  4. #4
    Registered User
    Join Date
    07-27-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: VBA Extract Numbers And Insert Words

    sorry, My Bad:
    Last edited by jamieray; 04-25-2012 at 06:58 AM.

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA Extract Numbers And Insert Words

    Jamie,

    You need to put code tags for your post #2. I have done it for you this time.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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