+ Reply to Thread
Results 1 to 9 of 9

Macro to determine if cell has value (within text), then copy value only

  1. #1
    Registered User
    Join Date
    04-19-2012
    Location
    Fullerton, CA, USA
    MS-Off Ver
    Office 2010
    Posts
    2

    Macro to determine if cell has value (within text), then copy value only

    Hello, I'm trying to help someone transfer data from a text report. I want to write a macro that will search line by line through the report and pull every work order number and date, and copy those two pieces of data into two different cells on another sheet. I can delimit the report to separate it into columns and make it a little easier, but I'm wondering if I can avoid this (in case another user is not familiar with how to delimit) and just pull the data from a single cell (with no delimiting). In which case, my data would look something like this:

    125890 RL-2250009 MACHINE #9 01/06/2012
    West poly let off not holding tension

    Trouble shoot. Suspect an air leak in the control electrical cabinet. Ran
    an air line directly from transducer to poly air clutch so they could
    continue running.
    25758 2.00
    53854 1.00
    127451 RL-2250009 MACHINE #9 02/10/2012
    Oil line leaking at nip 2

    Assesed job, No action required at this time.


    The data above would have each line of text within a single cell (non-delimited). And I want to grab every work order (6-digit value starting with "12"), copying that value in another column, and every date, copying that value into another column. Again, this data is within text in a single, non-delimited cell, and I want to repeat this for every work order on the report, ignoring any cell that doesn't have work order information. I'm familiar with macros to copy data from one cell into another sheet but this is another beast on its own.

    I've attached an example of this report I'm trying to format.
    Thanks to anyone that can take the time to help...
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Macro to determine if cell has value (within text), then copy value only

    Perhaps something like this:

    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to determine if cell has value (within text), then copy value only

    Maybe try this formula:

    B1: =IF(LEN(IF(LEFT(A1,2)="12",LEFT(A1,FIND(" ",A1)-1),""))=6,--LEFT(A1,FIND(" ",A1)-1),"")
    C1: =IF(B1<>"",RIGHT(A1,10),"")

    and drag down
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to determine if cell has value (within text), then copy value only

    I have added the formulas to your example and added a pivot table to collect all the data in a concise table format.

    Hope this helps.

    abousetta
    Attached Files Attached Files

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

    Re: Macro to determine if cell has value (within text), then copy value only

    try
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-19-2012
    Location
    Fullerton, CA, USA
    MS-Off Ver
    Office 2010
    Posts
    2

    Re: Macro to determine if cell has value (within text), then copy value only

    Thank you everyone for the great suggestions!!!

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to determine if cell has value (within text), then copy value only

    @jindon, could you explain this part:
    Please Login or Register  to view this content.
    I rarely use RegEx but I think it might help to learn some tricks.

    Thanks.

    abousetta

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

    Re: Macro to determine if cell has value (within text), then copy value only

    When string matches to the pattern

    .Pattern = "\b(\d{6})(?:\b.*)(\d{2}/\d{2}/\d{4})(?=\b)"

    You can refer submatches via Replace method of RegExp.

    Bold black part = $1
    Bold blue part = $2
    any set of bracket with a question mark will be ignored to be referred afterwards.

    .Replace(r.Value, "$1 $2")

    returns like 6 digits number and a space and the date.

    Then split function will split such string by a space.

  9. #9
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to determine if cell has value (within text), then copy value only

    Nice... thanks for the explanation.

+ 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