+ Reply to Thread
Results 1 to 10 of 10

Find specific text within workbook's name, copy and paste it to specific cell

  1. #1
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Find specific text within workbook's name, copy and paste it to specific cell

    Hi,

    I need to be able to find a specific text within changing-name workbooks, then copy that text and paste into a specific cell within the active sheet.

    I work with workbooks that all have a different name, but all have a common format, something like:

    "changingname-JA-restofname" Where a string of 2 letters will always be present and always after a dash (-). I need those 2 letters to be found, copied, and pasted into cell D2. I cannot use a count of characters from the beginning of the book's name, since they all have a different name and all have a different amount of characters before the "-".

    I'll appreciate your help with this.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: Find specific text within workbook's name, copy and paste it to specific cell

    As per your example
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Find specific text within workbook's name, copy and paste it to specific cell

    Hi Jolivanes,

    Your code is simple, yet effective. Works like a charm! Just have an additional question (since I didn't realize this earlier). How would the code be to only pick the first 2 letters of the book's name (and ignore the rest no matter what characters follow those 2 first letters) and paste it into the same cell (D2)?

    Thank you SO much for your help!

  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: Find specific text within workbook's name, copy and paste it to specific cell

    Hello axtryo,

    This will do it. If the name matches the pattern you posted then the 2 letters will be copied into "D2". If not "D2" will blank.

    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
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Find specific text within workbook's name, copy and paste it to specific cell

    Hi Leith,

    My bad for not explaining correctly. Your code works with the sample given in my original post, but as you correctly pointed out, it doesn't when that pattern is missing.

    The second scenario is when the book's name starts with the 2 letters needed, but is then followed by either letters or numbers w/o a dash, or there are dashes at other places within the name. These are 2 examples:

    RG120563-ALLEN-12216

    SM0235-STARMAN122016

    In this case, I just need to pick the first 2 characters, which are the letters I need pasted into cell D2, then ignore the rest of the book's name.

    Thank you again.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: Find specific text within workbook's name, copy and paste it to specific cell

    How would the code be to only pick the first 2 letters of the book's name (and ignore the rest no matter what characters follow those 2 first letters) and paste it into the same cell (D2)?
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Find specific text within workbook's name, copy and paste it to specific cell

    Jolivanes,

    Your code works perfect. I appreciate when experts like you take the time to help others. Thank you So much!

    I'm marking this post as solved.

  8. #8
    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: Find specific text within workbook's name, copy and paste it to specific cell

    Hello axtryo,

    Okay, but I am confused. You said in post #5 there were other patterns the macro needed to recognize.

    Now, miraculously it is all working fine.

  9. #9
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Find specific text within workbook's name, copy and paste it to specific cell

    Hi Leith,

    Sorry for the confusion. Jolivanes replied to the second scenario, and that code worked for that. The code you posted in response to my original post worked for that first case. In this case, I thank you both for your help!

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: Find specific text within workbook's name, copy and paste it to specific cell

    Thanks for letting us know.

+ 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. VBA Macro: Copy and Paste Specific Row Range based on the Specific Value in a Cell.
    By SolidSmoke in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-10-2016, 02:40 PM
  2. [SOLVED] Copy filename of source workbook to specific cell in specific tab in destination workbook.
    By MagicMan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2015, 10:29 PM
  3. [SOLVED] VBA to Find Specific Text, then Copy range to next open cell under specific text
    By Remotruker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2015, 10:59 AM
  4. Find specific Data copy and paste into Cell Macro VBA
    By kunmateo93 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2014, 10:17 AM
  5. Macro to copy specific line from text file and paste into specific cell in excel
    By keeneye in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-05-2013, 10:35 AM
  6. Replies: 0
    Last Post: 11-06-2012, 06:44 PM
  7. Find the specific text and copy and paste in another cell only if true.
    By SHARIB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2012, 03:14 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