+ Reply to Thread
Results 1 to 6 of 6

Strings, counting and moving words

  1. #1
    Registered User
    Join Date
    07-07-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    44

    Strings, counting and moving words

    I have created a macro that counts the words in a cell now i want the macro to cut a certain part of the sentence out and paste it in anther cell

    for example I want cell N5 which contains the original text (which can be different at times) and i want a macro to take the 7th word and onward and paste it to cell N6

    heres what i have so far to count the words and what i tried to create an if statement to take the 7th word and onward to paste to cell n6
    Please Login or Register  to view this content.

    THANKS!!!!!! please let me know if i can clarify anything
    Last edited by Leith Ross; 07-21-2011 at 03:31 PM. Reason: Added Code Tags

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Strings, counting and moving words

    You don't need VBA

    =MID(A1,FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),6))+1,99)

  3. #3
    Registered User
    Join Date
    07-07-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Strings, counting and moving words

    Thanks for the reply! I am almost there just one problem! is there anyway you can delete the text from the original cell that you copied to the new cell

    like cell A1 has some text "did the dog walk far from the park today"
    your formula in cell A2 "the park today"

    now can you delete the "the park today" from cell A1?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Strings, counting and moving words

    Hello ,

    Here is robust version of your macro. Leading and trailing spaces are ignored, and multiple spaces are counted as one. If there are not at least 7 words in the string then the macro leaves it unchanged.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Strings, counting and moving words

    Quote Originally Posted by rs585832 View Post
    Thanks for the reply! I am almost there just one problem! is there anyway you can delete the text from the original cell that you copied to the new cell

    like cell A1 has some text "did the dog walk far from the park today"
    your formula in cell A2 "the park today"

    now can you delete the "the park today" from cell A1?
    You need to do a Copy>Paste Values on A2 then clear A1.

  6. #6
    Registered User
    Join Date
    07-07-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Strings, counting and moving words

    Thanks guys!!! i got it

+ 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