+ Reply to Thread
Results 1 to 5 of 5

Need Macro or VBA to extract data from report to use in Excel

  1. #1
    Registered User
    Join Date
    10-23-2023
    Location
    Stockholm, Sweden
    MS-Off Ver
    MS Windows 10 Enterprise. Excel for Microsoft 365 MSO (V.2302 Build 16.0.16130.20806) 32-bit
    Posts
    11

    Need Macro or VBA to extract data from report to use in Excel

    Hello Forum,
    Hopefully, this is an easy problem to solve. I have a multi-page report (text file) showing delayed payments which is formatted for the users in this way. See also attachments.

    Sk?rmklipp.PNG


    I would like to use an excel macro or VBA to extract the fields in yellow (SSN and AMOUNT) from the report, and place these two pieces of data in a CSV or Text file as below. Note that the rows in the source report between each person's payment information is variable (as there are between 1 and x nr of REASONs for each delayed payment). Does anyone know how to glean such data from a text report and place in a text or CSV file?
    Regards and thanks!

    The goal:
    489-72-5078 3500
    499-42-1234 10000
    etc..
    See attachments. Source Delayed Payments Report and excel (i.e. the result i want to achieve)
    REPORT DELAYED PAYMENTS.TXT
    Excel-result.xlsx
    Last edited by JMB99; 11-03-2023 at 10:08 AM. Reason: Added attachments to my question

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Need Macro or VBA to extract data from report to use in Excel

    See the yellow banner at top page on how to attach a workbook. Please include both the text input file and the CSV/text output file, including sample expected results
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    10-23-2023
    Location
    Stockholm, Sweden
    MS-Off Ver
    MS Windows 10 Enterprise. Excel for Microsoft 365 MSO (V.2302 Build 16.0.16130.20806) 32-bit
    Posts
    11

    Re: Need Macro or VBA to extract data from report to use in Excel

    I've now attached the original source report and the excel i would like to achieve. /Jeff

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hello, try this !


    According to your attachment a VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
            
    ThisWorkbook.Path "\REPORT DELAYED PAYMENTS.TXT"
            
    If Dir(V) = "" Then V Application.GetOpenFilename("Text files,*.txt"): If False Then Exit Sub
            R
    & = FreeFile
            Open V 
    For Binary As #R
            
    Split(Input(LOF(R), #R), "SSN: ")
            
    Close #R
            
    If Not V(0Like "*DELAYED PAYMENTS *" Then Beep: Exit Sub
            ReDim W
    (1 To UBound(V), 1)
        For 
    1 To UBound(V)
            
    W(R0) = Split(V(R), vbCrLf)(0)
            
    W(R1) = Val(Split(V(R), "AMOUNT:")(1))
        
    Next
       With Blad1
           
    .UsedRange.Clear
           
    .[A1].Resize(UBound(W), 2) = W
           
    .UsedRange.Borders.Weight 2
       End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Or this ...


    To create a text file from a text file Excel is very not necessary ‼

    Anyway, according to your missing csv attachment , another VBA demonstration for starters :

    PHP Code: 
    Sub Demo2()
            
    ThisWorkbook.Path "\REPORT DELAYED PAYMENTS.TXT"
            
    If Dir(V) = "" Then V Application.GetOpenFilename("Text files,*.txt"): If False Then Exit Sub
            F
    % = FreeFile
            Open V 
    For Binary As #F
            
    Split(Input(LOF(F), #F), "SSN: ")
            
    Close #F
            
    If Not W(0Like "*DELAYED PAYMENTS *" Then Beep: Exit Sub
            Open Replace
    (V".txt"".csv", , , 1) For Output As #F
        
    For R& = 1 To UBound(W)
            Print 
    #F, Split(W(R), vbCrLf)(0) & "," & Val(Split(W(R), "AMOUNT:")(1))
        
    Next
            Close 
    #F
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

+ 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. Replies: 5
    Last Post: 07-31-2014, 12:51 PM
  2. Macro to extract data from 4 different spreadsheets into a master report.
    By sebastosh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2014, 09:37 AM
  3. [SOLVED] Attempting to extract data from a report
    By jkarow in forum Excel General
    Replies: 2
    Last Post: 04-01-2012, 11:39 AM
  4. Run Macro to generate report in Access from excel data, then print PDF from Excel?
    By Danimarie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2012, 07:50 AM
  5. Replies: 0
    Last Post: 02-14-2012, 12:31 PM
  6. Make report (extract data)
    By mido21 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2011, 09:47 AM
  7. Macro to Extract Values from Master.xls to Report.xls
    By prkhan56 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-02-2005, 08:06 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