+ Reply to Thread
Results 1 to 5 of 5

Compile Numerical data based on Keywords in a Sentence

  1. #1
    Registered User
    Join Date
    12-27-2013
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2013
    Posts
    14

    Compile Numerical data based on Keywords in a Sentence

    Hello,

    I am looking for VBA code that will allow me to:

    1) Import a .log file into excel.
    2) Look for key words in a line of text.
    a) The lines of text I am interested in will all have the pattern: X purchases the Y for Z dollars of his allowance.
    3) If the key words are in a line of text, extract the number within that same line of text.
    4) Create a category for the subject of that line of text.
    5) Add the number within the line of text to two separate cells:
    a) To one cell that tracks the total spent for the subject of that line of text.
    b) To one cell that keeps a running total for the entire document.


    Example of a typical .log file is as follows:

    The store opened on Tuesday afternoon.
    Dexter purchases the Vase for 8 dollars of his allowance.
    Ralph purchases the Vase for 7 dollars of his allowance.
    The store closed on Sunday morning.
    The store opened on Monday evening.
    Carl purchases the Vase for 6 dollars of his allowance.
    Jim purchases the Vase for 8 dollars of his allowance.
    Ralph purchases the Vase for 10 dollars of his allowance.
    The store closed on Wednesday afternoon.
    The store opened on Thursday evening.
    Ralph purchased the Vase for 11 dollars of his allowance.
    Carl purchases the Vase for 7 dollars of his allowance.

    I would need Categories that show the following data from the text above:
    Dexter = 8
    Ralph = 28
    Carl = 13
    Jim = 8
    Total store profit = 57

    Thanks in advance
    Attached Files Attached Files

  2. #2
    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: Compile Numerical data based on Keywords in a Sentence

    Hello phoenixjasper,

    Welcome to the Forum!

    The attached workbook produces 3 columns: Name, Amount, Total. The Total column is actually the running total for each person. Have a look a tell me if this close to what you want.

    There is a button on "Sheet1" named "Run". Clicking this button will prompt you for the file to open. It will list ".txt" and ".log" files in a folder. You can also choose "All Files" if you need to.

    Here is the macro attached to the "Run" button. This is already installed in the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    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!)

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

    Re: Compile Numerical data based on Keywords in a Sentence

    This should do
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-27-2013
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2013
    Posts
    14

    Thumbs up Re: Compile Numerical data based on Keywords in a Sentence

    Quote Originally Posted by Leith Ross View Post
    Hello phoenixjasper,

    Welcome to the Forum!

    The attached workbook produces 3 columns: Name, Amount, Total. The Total column is actually the running total for each person. Have a look a tell me if this close to what you want.

    There is a button on "Sheet1" named "Run". Clicking this button will prompt you for the file to open. It will list ".txt" and ".log" files in a folder. You can also choose "All Files" if you need to.

    Here is the macro attached to the "Run" button. This is already installed in the attached workbook.
    [/code]

    Thank you so much, Leith Ross! Your code was awesome and got me pretty much what I was asking for. The 'Run' button was super helpful, too! Very easy to work everything^^




    Quote Originally Posted by jindon View Post
    Please Login or Register  to view this content.
    Jindon, thanks a bunch! This code helped me understand more about how VBA works. It also gives me the chance to build on my math project for my kids to possibly include other 'key words'. This was awesome! Tysm!

  5. #5
    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: Compile Numerical data based on Keywords in a Sentence

    Hello phoenixjasper,

    You're welcome. Glad I could help out.

+ 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. automatic sorting names based on numerical data
    By Littlesimon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2015, 11:46 PM
  2. Automatic sorting names based on numerical data
    By Littlesimon in forum Excel General
    Replies: 5
    Last Post: 01-15-2015, 05:45 PM
  3. [SOLVED] HDI - Return multiple keywords in a text column based on a set of available keywords
    By zneiley in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-25-2013, 01:32 PM
  4. Trying To Write A Complete Sentence Based On Columnar Data
    By Godzilla in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-14-2008, 10:50 PM
  5. Numerical error in IF-sentence
    By MnO in forum Excel General
    Replies: 2
    Last Post: 12-06-2006, 10:37 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