+ Reply to Thread
Results 1 to 21 of 21

How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so on

  1. #1
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Question How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so on

    My Requirement is

    I have a String in A1
    CHEMICAL, PETROCHEMICAL MECHANICAL AND METALURGICAL TRAINING CENTRE

    I want
    A2 : CHEMICALPMAMTC [string before the comma followed by all the First Letters without spaces]
    A3 : CHEMICALPETROCHEMICALMECHANICALMETALURGICALTRAININGCENTRE
    A4 : C H E M I C A L , P E T R O C H E M I C A L M E C H A N I C A L A N D M E T A L U R G I C A L T R A I N I N G C E N T R E
    A5 : C H E M I C A L , P E T R O C H E M I C A L A N D T R A I N I N G C E N T R E [REmove any two words if the number of words longer than 5 in the given string]
    A6 : CHEMICALXXXPETROCHEMICALXXMECHANICALXXXANDMETALURGICALXXXTRAININGXXXCENTRE [A three character string between each word and no spaces]
    A7 : Random special characters in between string - spaces stripped
    A8 : Split the A6 - at random locations but put in multiple lines in the same ceel like [CHE MICAL CHAR(12) PET RO CHEM CHAR(12) ICAL and so on]
    A9 : Content of A6 0 -> Replace the character which occurs very minimum in the string with another alphabet [A to E]


    This is my first question in the forum, hoping to get a solution.

  2. #2
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    For my requirement of A2 I had worked a solution to split the name into multiple part using the SPACE and use MID of 1 to get the tags as I need.
    Hence A6 is also resolved automatically just by concatenating the text together.

    For my requirement for A3 I got the solution it goes like this

    Please Login or Register  to view this content.

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    or maybe a UDF
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Here's up to A6.

    Need to see the result from A7 to A9 in workbook.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Thank you pike and jindon.
    shall check this and revert.

    Jindon ..will this script work for range?
    /

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    The code I posted works only for the data in A1.

    Posting a workbook with before/after format with good explanation would help.

  7. #7
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Thumbs up Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    HI jindon,

    The script works as expected without any single issue.

    I had made few corrections to represent the data in a SINGLE row rather than a single column.

    Had given a few headers for my reference.

    I would like this to work for a range I select COLUMN A - all the data should be populated in column B to F [G..H ..J].

    Thank you for the quick response on this. Pasted the code and attached the file I used to test this ..Updated the Sub in the attached file also.

    Please Login or Register  to view this content.
    Regards
    Sundharesan R
    Attached Files Attached Files

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Jindon,

    For some reason the below code is ending in error at line " pref = .Execute(txt)(0).submatches(0)"

    Can you please read my attachment sent few minutes ago too. I had made few changes to it.

    Regards
    Sundharesan R
    Last edited by jeffreybrown; 06-18-2013 at 12:54 PM. Reason: Removed needless quotes

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    You'd better upload a variety of pattern of string and the result that you want.

    I don't want to continue this without seeing actual data pattern and the result.

  11. #11
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Dear Jindon,

    I think I had not put my requirements clearly in the first place itself. As this was my first post in the forum - and very new to VBA - i always work with simple mathematical and simple string formulas in excel. I am very sorry for troubling you. Thank you for your time.


    I attach the Complete requirement in detail.

    Regards
    Sundharesan R
    Attached Files Attached Files
    Last edited by jeffreybrown; 06-18-2013 at 12:54 PM. Reason: Removed needless quotes

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    There is a difference in result.

    You eliminated "AND" from some of your original result, but not in your attached (&).

    I need more different example data to be processed and EXACT result that you want.

  13. #13
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Okay - Shall update it with a completely a different string. Sorry for that.

  14. #14
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Jindon,

    I had put three examples now

    & - actually in the original string & to be stripped. and i had included special characters range in another requirement.

    Attached the new file.
    Regards
    Sundharesan R
    Attached Files Attached Files

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Explain more about stripping "AND", "&".

    It doesn't seem to be consistent.

  16. #16
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Jinton

    Pleasr strip & if it is part of name.
    in one sample specific set of special characters are there to inclodr in string
    AND : It is a normal word. as it happen to be part of a missing word of is not there in one of the samples.

    Treat and as a word.
    Regards
    Sundharesan

  17. #17
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Jindon,

    I am sorry for the delayed reply.

    & - as a special character should be stripped from the string when data samples are formed.
    AND - Treat this a Normal word only.

    YOUR SCRIPT which you had given for Column is working fine, I had placed a string without COMMA which resulted in a problem. I am sorry for that.

    Probably I should have told you there will be data without Last name and First name separators.

    Please let me know if you can provide the rest of the samples also.

    Regards
    Sundharesan R
    Last edited by jeffreybrown; 06-18-2013 at 12:54 PM.

  18. #18
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,317

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    @sundharesanr,

    Administrative Note:
    • As per Forum Rule #12, please limit quotes to only that which is necessary -- otherwise it's just clutter...Thanks.
    HTH
    Regards, Jeff

  19. #19
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Jindon,

    I am extremely sorry for the much delayed response.

    As such the issue of the error is on my part - if there is COMMA in the INPUT it results in a error.

    Otherwise your script is works like a magic and does all the tasks for 10,000 strings in quick time.

    Thank you for that.

    Now to the issue of AND and &.

    Please remove ALL special characters in the INPUT String.
    AND - Treat it as a normal word like another word.

    Regards
    Sundharesan R

  20. #20
    Registered User
    Join Date
    06-15-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    HI jeffreybrown,

    Can you please close this thread. I will open a fresh one.

    The solution given my Jinden works fine for first 6 requests.

    I will start a new thread for the remaining.

    Regards
    Sundharesan R
    Also guide me how to post closure comments and give a rating or STARs to the person who helped.

  21. #21
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,317

    Re: How to do this Multiple variations of a string in cell A2 , A3, A4 , A5 and A6 and so

    Hi Sundharesan R,

    FORUM MODERATORS REQUEST:

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Thanks.

    To give reputation, just look below the persons name on their post and click on the star with Add Reputation. That's all that is needed.

+ 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