+ Reply to Thread
Results 1 to 13 of 13

add under score before 4 digit numbers

  1. #1
    Registered User
    Join Date
    01-20-2014
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    7

    add under score before 4 digit numbers

    i'm new to vba

    and i'm trying to write a macro,

    that adds a underscore before a 'number' when only 4 digits are together

    like "asdvgb2345qwerty14567uimh"
    will be converted to asdvgb_2345qwerty14567uimh


    this is my code

    Please Login or Register  to view this content.


    can any one suggest whats wrong with my logic??
    i have done programming on c++,and java but completely new to vba
    Last edited by vkpajeet; 01-23-2014 at 10:56 AM.

  2. #2
    Registered User
    Join Date
    01-20-2014
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: add under score before 4 digit numbers

    is there a simpler logic and way?

  3. #3
    Registered User
    Join Date
    01-20-2014
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: add under score before 4 digit numbers

    sorry, i'm new, was unaware of the rules

  4. #4
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: add under score before 4 digit numbers

    Trie this

    Please Login or Register  to view this content.
    function:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: add under score before 4 digit numbers

    if your string always the same you can use this code. but its not goint work if your data has diffrent types
    this code assumes that you data in column A and result will be column B
    Please Login or Register  to view this content.
    Give Feedback and Click(*)

  6. #6
    Registered User
    Join Date
    01-20-2014
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: add under score before 4 digit numbers

    Quote Originally Posted by G e r a r d View Post
    Trie this

    Please Login or Register  to view this content.
    function:

    Please Login or Register  to view this content.

    its not working as exactly i want it to work.

    it adds underscore before any cluster of characters that has more than 4 digits together..

    i want underscore only before cluster that has exactly 4 digits together

  7. #7
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: add under score before 4 digit numbers

    Modified fuction will only add _ to first cluster of 4 numbers

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-20-2014
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: add under score before 4 digit numbers

    Quote Originally Posted by venkatpvc View Post
    if your string always the same you can use this code. but its not goint work if your data has diffrent types
    this code assumes that you data in column A and result will be column B
    Please Login or Register  to view this content.

    these are working but only for one cluster of numbers in a string..

    like if the string is abdsf3456asdfg5678as
    so this code is converting to abdsf_3456asdfg5678as
    but i want it to be like this abdsf_3456asdfg_5678as

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: add under score before 4 digit numbers

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  10. #10
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: add under score before 4 digit numbers

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-20-2014
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: add under score before 4 digit numbers

    Quote Originally Posted by G e r a r d View Post
    Modified fuction will only add _ to first cluster of 4 numbers

    Please Login or Register  to view this content.



    this is also adding underscore at the starting of the string and adding only one underscore for only one cluster, what if there are multiple cluster?
    i'm new to this vba, so i'm not able to understand your code, however i will be happy if it serves my purpose

  12. #12
    Registered User
    Join Date
    01-20-2014
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: add under score before 4 digit numbers

    Quote Originally Posted by venkatpvc View Post
    Please Login or Register  to view this content.

    this is fine but, it is converting this to 1904758968
    _1904_758968

  13. #13
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: add under score before 4 digit numbers

    ok this should be do it what you looking for.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Extract 4 digit common numbers from 5 digit numbers
    By ameque in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-24-2013, 01:09 AM
  2. Replace all one-digit number with two-digit numbers
    By sandykunaish in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-20-2013, 09:56 AM
  3. [SOLVED] macro to extract 9 digit numbers as well as alpha numberic 9 digit numbers from txt file
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2012, 10:15 AM
  4. Replies: 2
    Last Post: 03-20-2012, 06:30 PM
  5. To count numbers with 4 digit/5 digit with given Range.
    By ebin charles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2012, 08:49 AM

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