Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Macro to extract data from report
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    New Member
    Join Date
    May 2019
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to extract data from report

    Irony is that with the way I'm currently copy/pasting (not using a macro), the formula can just be a MID formula.

    Obviously though I want something more robust. I really need a macro that will just take everything I need and wrap it up nicely for me. Heh. Anyway, any help would be appreciated.

  2. #12
    New Member
    Join Date
    May 2019
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to extract data from report

    Actually, is there a way to copy data from a column into another column, based on certain criteria?

    For example, data in column C that starts with an 'S' will go into column K, starting in cell K5. Anything that doesn't start with an 'S' will go into column J, starting with J5. Does this make sense?

    I want a formula that I can have in columns J and K that will auto-populate with data once I paste in my original data..hope this makes sense.
    Last edited by Alex881; Sep 12th, 2019 at 03:49 PM.

  3. #13
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,985
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: Macro to extract data from report

    Quote Originally Posted by Alex881 View Post
    I really need a macro that will just take everything I need and wrap it up nicely for me. Heh. Anyway, any help would be appreciated.
    See if this comes anywhere near what you want. It is a bit hard for me to be sure as I think many of the spaces in your data have disappeared when you pasted the sample data into post 1.

    Anyway, give it a try with a copy of your data.
    I have assumed all that data from post 1 is actually in column A.

    Code:
    Sub Extract_Data()
      Dim a As Variant, b As Variant, CurrCust As Variant
      Dim i As Long, k As Long
      Dim s As String
      
      a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
      ReDim b(1 To UBound(a), 1 To 2)
      For i = 2 To UBound(a) - 1
        s = LCase(a(i, 1))
        Select Case True
          Case s Like "address:*"
            CurrCust = Mid(a(i - 1, 1), 6, 5)
            If Not CurrCust Like "#####" Then CurrCust = "Check??"
          Case s Like "order status via card*"
            k = k + 1
            b(k, 1) = CurrCust
            b(k, 2) = Mid(a(i + 1, 1), 18, 8)
        End Select
      Next i
      Range("M2:N2").Resize(k).Value = b
    End Sub
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

  4. #14
    New Member
    Join Date
    May 2019
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to extract data from report

    That's right - all the data are in column A. Every time I paste data into my Excel sheet from this software program, the data go into column A.

    I tried using your Macro on some sample data. I just got an error that states '400'.

    Here's some more fictional data (all in column A):
    xxxxx08a.p 7.8.50 *ANALYSIS REPORT Date: 09/09/19
    Page: 1 P999999 Time: 14:57:59
    A/R CAR BILL-TO NAME CITY ST PHONE CR LIMIT HOLD REASON
    REP NBR CODE
    01 17999 BOGDAN HOME CART SAN ANTONIO TX 555-555-5555 009,999,999 yes C1
    Address: 9999 119TH STREET Zip: 55555
    Ord Date Sales Bill-To Purchase Order Doc Amt S/O Ship Credit
    Order Status Via Card
    09/09/19 S7777777 1000000 iv000000g8 2,250.00 HD FXGR
    Contact Name:donald duck/ purch 555 555 5555
    C/S Rep: Daffy Doodles
    ---------------
    CAR Hold Total: 2,250.00
    CAR Commit Total: 0.00
    ------------------------------------------------------------------------------------------------------------------------
    ZZ 25000 SUPPLY'S INC NY 999.999.999 009,999,999 yes C1
    Address: 19999 BIG AVENUE Zip: 99999
    Ord Date Sales Bill-To Purchase Order Doc Amt S/O Ship Credit
    Order Status Via Card
    09/09/19 S8888888 10999999 6049999 4,157.85 HD FXGR
    Contact Name:EMAIL JOHN DOE JOHNDOE@GMAIL.COM
    C/S Rep: Amelia Prayers
    ---------------
    CAR Hold Total: 4,157.85
    CAR Commit Total: 0.00
    ------------------------------------------------------------------------------------------------------------------------
    Page: 2 PRDDDD Time: 14:57:59
    A/R CAR BILL-TO NAME CITY ST PHONE CR LIMIT HOLD REASON
    REP NBR CODE
    hh 55555 CALIFORNIA INC SAN FRANCISCO CA 555-555-5555 009,999,999 yes C1
    Address: BIG ROAD 120 Zip: 66666
    1666 BIG CITY AVENUE
    Ord Date Sales Bill-To Purchase Order Doc Amt S/O Ship Credit
    Order Status Via Card
    09/09/19 S7666666 16666666 099999BERT 2,342.34 HD FXSURE
    Contact Name:EMAIL JANE APOSTLE
    C/S Rep: JARDIN HARPER
    Ord Date Sales Bill-To Purchase Order Doc Amt S/O Ship Credit
    Order Status Via Card
    09/09/19 S7366666 17777777 090919BERNIE 7,450.41 HD FXGR
    Contact Name:EMAIL JANE APOSTLE
    C/S Rep: JORD CARVER
    ---------------
    CAR Hold Total: 9,792.75
    CAR Commit Total: 0.00

    Also, see the imgur link for a picture of what that data look like (one example):

    https://imgur.com/a/Yo6OUhT
    Last edited by Alex881; Sep 13th, 2019 at 10:46 AM.

  5. #15
    New Member
    Join Date
    May 2019
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to extract data from report

    Right now I'm using this to extract the correct data from each row (assuming today's date is the order date). I don't know how (yet) to find anything with a '**/**/**' type format.

    =IF(SUMPRODUCT(--ISNUMBER(FIND("009,999",A5)))>0,MID(A5,6,5),"")&IF(ISNUMBER(FIND(" 09/13/19 ",A5)),MID(A5,18,8),"")

    I copy the above formula down an entire column - it makes the correct decisions. It leaves all cells it doesn't need to touch blank, while extracting a customer's ID # and a customer's order #.

    Having said that, it is possible that a customer's ID # will show up twice - this is because the software program makes new pages and if part of the data is on one page and part is on another, then the data repeat in that regard (if that makes sense). It's not a huge issue, but it's something I'm thinking about..

    EDIT: Nevermind, this formula is better (using search):

    =IF(SUMPRODUCT(--ISNUMBER(FIND("009,999",A15)))>0,MID(A15,6,5),"")&IF(ISNUMBER(SEARCH(" **/**/19 ",A15)),MID(A15,18,8),"")
    Last edited by Alex881; Sep 13th, 2019 at 11:09 AM.

  6. #16
    New Member
    Join Date
    May 2019
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to extract data from report

    Further simplified the above edited formula to:

    =IF(ISNUMBER(FIND("009,999",A5)),MID(A5,6,5),"")&IF(ISNUMBER(SEARCH(" **/**/19 ",A5)),MID(A5,18,8),"")

    This works - it extracts the correct data everytime.

    Now I need something robust that will take all this data and put it in two columns (one column that has the customer's five digit ID # and a column to the right of that one that has the appropriate eight digit alphanumeric string).

  7. #17
    New Member
    Join Date
    May 2019
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to extract data from report

    I've separated the data that show in that one column by using two formulas:

    (1): =IF(LEN(K5)=5,K5,"")

    &

    (2): =IF(ISNUMBER(SEARCH("S*******",K5,1)),K5,"")

    This now makes my data show up in two columns. Now it's a matter of getting the appropriate data to show side by side..if that makes sense..

  8. #18
    New Member
    Join Date
    May 2019
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to extract data from report

    Nevermind. I got help and was able to figure out the entire thing. Not using a macro, just several columns worth of formulas and then a PivotTable that I have to refresh when I paste in new data to column A.

  9. #19
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,985
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: Macro to extract data from report

    Quote Originally Posted by Alex881 View Post
    .. was able to figure out the entire thing.
    Glad you got something that worked for you.

    Do you have to do this task regularly? I'm pretty sure we would be able to get a macro going for you with a bit more effort.
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

  10. #20
    New Member
    Join Date
    May 2019
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to extract data from report

    I do this task several times a day. However, the way it works now is fantastic. All I really do is paste data then refresh a PivotTable. I genuinely appreciate the offer for a macro, but at this point I'm very satisfied! Thank you so much for the assistance though.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •