+ Reply to Thread
Results 1 to 4 of 4

Automatically emailing a range of cells if the cell values = other cell values.

  1. #1
    Registered User
    Join Date
    06-13-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Automatically emailing a range of cells if the cell values = other cell values.

    Hello, this is my first post here and I am a bit of a newb and experimentor with VBA. I have a bit of a problem to solve and can't seem to solve it myself, and was wondering of any of you may know of a solution to this anywhere.

    What im trying to achieve is to send an automated report to myself. This copies the cell range and then emails that range to me. To do this I run windows schedular to open a specific Excel spreadsheet at a specific time each day. In the spreadsheet I have set this up to automatically run the below script in the background:

    Please Login or Register  to view this content.
    It all works well! Now I wish to add a function to the source when a date or value in a cell equals the same as a date/value in another cell then the above Send_Range() contunies to run. I think I need to insert the code within the Send_Range() befoe the Active.Range() function? But I could be wrong.

    I need to keep this as simple as possible so that I also understand it too, I understand these codes but can't seem to include the "if" function below to run.


    Please Login or Register  to view this content.

    Basically the function would run if cell A3 = B3 and so on but if non of them are equal then the email does not send.

    Appologies if this seems silly or if it is a good laugh, I'm glad I made you smile to the more advanced programmers but I really want to understand this. Any help would be greatly appreciated.

    Thank you.

  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: Automatically emailing a range of cells if the cell values = other cell values.

    Hello Apollon,

    Welcome to the Forum!

    VBA does not compare arrays directly like Excel. You have to compare the cells individually or use some of Excel's functions. In this version of the macro, the columns are compared to each other using the MATCH function. Any row that does not match will generate an #N/A error. The function returns an array of the matching row numbers and any errors. Each item in the returned array is checked for an error code. If there is an error then the macro exits. If no errors are found the macro Send_Range is called.
    Please Login or Register  to view this content.
    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
    Registered User
    Join Date
    06-13-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Automatically emailing a range of cells if the cell values = other cell values.

    Thanks Leith,

    I've added your code to the VBA and have had it run successfully, however when it runs it still calls Send_Range even if the RngA and RngB ranges do not match. If it does not match it should'nt call Send_Range.

    To be exact, I need to match the contents of the dates in RngA with the dates in RngB. For example, if A1 = B1 then it would call Send_Range and so on down the list of the range A1:A7 (Today's Date) matching with the corresponding cell in the range B1:B7 (Alert Date).

    Here is my table:

    Today's Date Alert Date
    10/06/2012 11/06/2012
    10/06/2012 12/06/2012
    10/06/2012 13/06/2012
    10/06/2012 14/06/2012
    10/06/2012 15/06/2012
    10/06/2012 16/06/2012
    10/06/2012 17/06/2012

    Here is the source i am now using.

    Please Login or Register  to view this content.

    Thanks for your help with this I really appreciate It. And i appologise if im not very clear.
    Last edited by Apollon; 06-14-2012 at 01:40 AM.

  4. #4
    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: Automatically emailing a range of cells if the cell values = other cell values.

    Hello Apollon ,

    The macro I wrote will not call the macro Send_Range if the columns do not match. I have tested it to be sure. There is something else invoking the macro. You should post a copy of your workbook for review. If it contains any sensitive or confidential information, please redact it before you post it.

+ 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