+ Reply to Thread
Results 1 to 9 of 9

Automatically save data in a text file, based on the value of a cell

  1. #1
    Registered User
    Join Date
    08-03-2018
    Location
    Preston
    MS-Off Ver
    Excel 2016
    Posts
    10

    Automatically save data in a text file, based on the value of a cell

    If the column "Number of days worked in the last 14-day period" is >=13, I would like to automatically save the dates and number of days and names in a text file.

    I have had a look at sending an email, but from what I can see I would need to click send, and I want this to be completely automatic.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Automatically save data in a text file, based on the value of a cell

    But what should be the "trigger" to start the procedure - shall it be initiated manually, by clicking a button, or done before closing the file, or just after data was added, o
    And what if you changed data - it was 13 then 14 - shall it be written again?
    How about corrections like was 13 deleted 1 day 12 remains ?

    BTW. procedures to send mail could be also fully automatic - see for instance my favourite description here: http://www.rondebruin.nl/win/s1/outlook/amail4.htm or on other Ron's pages.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    08-03-2018
    Location
    Preston
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Automatically save data in a text file, based on the value of a cell

    I just need to keep it as simple as possible. It is very unlikely that the data will change once entered, so I'm not concerned about that.

    Id like the "trigger" to be after the data has been added, So if the number days is >=13 the file is appended.

    I would love the email option if fully automatic, but I don't have a great understanding of the code involved and wouldn't be able to edit it for what I need.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Automatically save data in a text file, based on the value of a cell

    The "trigger" code in worksheet code module
    Please Login or Register  to view this content.
    Main code in regular module (do not forget to change mail address to real one, and make sure you have outlook instaled):
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-03-2018
    Location
    Preston
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Automatically save data in a text file, based on the value of a cell

    Hi Kapper,

    Thanks for the code, it is working although when a cell in column B is >=13 if I update any other cells in the row, it sends another email.

    Can this be changed so it only sends the email if column B is >=13 and no other cells have an influence?

    Many Thanks.

    Dean

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Automatically save data in a text file, based on the value of a cell

    There is the issue with your layout which can make it not working (not only about mails bat at all). in some weeks (for instance week 30) you have first column for given week (the column which is used by your formula in column B) containing NUMBER OF DAYS WORKED, while in other weeks - like week 14 this year or week 13 of 2019 there is BASIC HOURS.
    Going back to our code, try such change in worksheet code (replace old code, do not add whole second procedure with the same name):
    Please Login or Register  to view this content.
    it will send mail only when changes are made to column leading to change in column B (ignoring changes to say BASIC PAY RATE, HOLIDAY MONEY PAID, etc.

  7. #7
    Registered User
    Join Date
    08-03-2018
    Location
    Preston
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Automatically save data in a text file, based on the value of a cell

    I will be updating all weeks to include the column for NUMBER OF DAYS WORKED. The additional code has fixed the issue I was having.

    I have now been looking at which cells I want to paste into the email. I have found the. Range("A" & myrow & ":D" & myrow), but when I try to adjust it to include column G, I either just get an error or all colums from A to G. Not sure if .Range is is what I need, I have tried .Cells and using Union, but I'm getting nowhere fast.

    Really appreciate all your help.

    Cheers,

    Dean

  8. #8
    Registered User
    Join Date
    08-03-2018
    Location
    Preston
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Automatically save data in a text file, based on the value of a cell

    I have figured it out! no idea if there is a cleaner way of doing this... the main thing is that it worked.

    Please Login or Register  to view this content.

  9. #9
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613
    Surely, could be written in a more compact way, but as it is working, I'd leave it as is. May be just singł cells referred as single cells, ie:
    Please Login or Register  to view this content.
    And the same way with G4

+ 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. [SOLVED] Save Each Worksheet as a PDF File and Name each File Based on a Cell Value in each Sheet
    By hamidxa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2016, 09:36 AM
  2. [SOLVED] Automatically save data locally (not referencing a server) when closing the file
    By JET2011 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-14-2016, 10:56 AM
  3. Automatically save file with cell value + copy cell values to other workbook
    By notquitetheguru in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-10-2013, 07:04 AM
  4. Programatically save in Quarter file based on "text-date" in cell
    By ron2k_1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-29-2012, 08:55 PM
  5. Save rows as text file & name file from a cell
    By nebraska in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-01-2011, 05:39 PM
  6. automatically produce save as file name by value in a cell
    By dittotharappel in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-25-2009, 09:13 AM
  7. Automatically save file based on cell value
    By Craig in forum Excel General
    Replies: 0
    Last Post: 02-27-2005, 07:06 PM

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