+ Reply to Thread
Results 1 to 16 of 16

VBA Coding To Automatically Send Emails Within a Column of Values

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    VBA Coding To Automatically Send Emails Within a Column of Values

    Hi Relatively new to the forums: been browsing the majority of post to try and edit the VBA codes to my needs. I've yet to succeed with my attempt.
    Project in short: I'm creating a complaints log, Straight forward stuff complaints are entered and edited via userforms which then place the data onto the Database tab, what I'd like to implement is an email system that will automatically send an email if a certain complaint goes over a certain date (lets define this variable as X). I want the VBA code to look at column T and see if there is a 1 if not it should look at column S to find the a Value (this is an if statement saying if the date difference X goes over a set limit put a 1), if it does send an email from that particular row then place a 1 in column T. This should hopefully eliminate spam.
    This will increase in size (so a predefined range won't work) don't take the format I've uploaded as the actual document.
    I'd like the email to contain certain values within that specific row, Customer ID, Customer Name and Department
    Now I've browsed forums and looked on a few sites (that Rob site about sending emails), Nothing has met the criteria I'm after
    I've attached the workbook any help will be greatly appreciated
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Let me simplify these words as they are confusing and are not all necessary.

    In a predefined column (lets say column G) there will be a list of 1's and 0's. If a "1" is in the cell then i want to send an email (the address will be in the same row in another column, changes for different complaints) if there is a "0" then we don't want an email to be sent

    sooo..


    the vba code basically needs to look down the column, find the "1"'s and send the email automatically to the relevant address.

    I am comfortable with sending emails via vba, the part i am struggling with is looking down the entire column as apposed to a specific cell.

    I hope someone can help

    Kind Regards

    Lance

  3. #3
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Quote Originally Posted by zeeez View Post
    In a predefined column (lets say column G) there will be a list of 1's and 0's. If a "1" is in the cell then i want to send an email (the address will be in the same row in another column, changes for different complaints) if there is a "0" then we don't want an email to be sent
    I haven't looked at your workbook or tried to interpret your first post, so see if this gets you started:
    Please Login or Register  to view this content.
    Post responsibly. Search for excelforum.com

  4. #4
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    So, something like:

    Please Login or Register  to view this content.
    Change the Range to match the starting cell of your column, I guessed it was Database!S3. This will read the entire column into an array, then loop through the array looking for 1's. When it finds one, it will call the SendEMail procedure, passing it a range of column A in the selected row. SendEMail could start like this:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Hi there Wallyeye and Chippy, sorry for the delayed reply just turned the pc on!
    The code doesn't seem to do what I want to it to do, I'll reiterate the points to help clarify what I need the code to do:

    Look through many rows down Column "T" to Find any cells with the value "1"

    IF "1" is Found Send Mail via outlook, the body of the email will consist of the information in the relevant rows in column A B and C

    the code needs to look at all the rows in that column, and not just stop at the first "1"

    However IF a 0 is within Column T do nothing

    if you can post a workbook example as opposed to code I'd appreciate it

    the email address is a fixed email address which can be hard coded

  6. #6
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    If you paste the code from my post into a new module in the workbook you posted, and step through it using the F8 key, you will see that it starts at the given location, looping through all values in the column. Each time it finds a 1, it will call the SendEMail routine, passing it a range object pointed to column A of the found row. The SendEMail template I posted puts data from the found row into arrComplaint, where you can use it to send your email using your standard process.

  7. #7
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Hi there Wallyeye
    what does that Star entail with in find.(What="*")
    I've stepped into the code (done that prior to my first reply) it doesn't select the row and the arrcomplaint value is empty. Maybe it's me not being able to understand where to look at sorry for the endless questions!

  8. #8
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    The Star (asterisk) will match any value in the given range.

    Did you change the rngColumnStart to point to the first 0/1 value?

  9. #9
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    I'll test it first thing tomorrow when I have the code in front of me unfortunatly I don't have access to it at the moment! If I have any issues I'll just update you with the troubles I have.

    Appreciate your help thus far

  10. #10
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Hi again,
    I've attached the code I've generated to send emails, the only issue I seem to be having now is extracting the required data from that row, I'm not to sure how the arrComplaint works. I've tried using the celloffset(0,0).Value but it doesn't seem to work

    Any help is apperciated!
    and once again thanks wallyeye for the help
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    So, it would end up looking at values within the arrComplaint array:

    Please Login or Register  to view this content.
    You would change the second 1 to bring up different columns from the database, i.e.:

    arrcomplaint(1,8)

    would show the department.

  12. #12
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Thanks once again wallyeye, I'll test the code out first thing Monday morning (don't have access to the actual database currently) I'll be sure to mark the thread as solved if the code works (which I'm sure it will)! If not I'll just pester you a little more

  13. #13
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Hi again, Got the code working only thing I need now is for it to write a "1" within a column R, using the arrComplaint Variable.

  14. #14
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    You would probably do the update within your CheckDatabase module, right after the SendEMail call:

    Please Login or Register  to view this content.
    18 being the column number of column R. It would be just as easy to do it within SendEMail:

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    08-01-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Thanks a lot Wallyeye! I've given you rep for the posts and I owe you

  16. #16
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: VBA Coding To Automatically Send Emails Within a Column of Values

    Cool! Glad to be of help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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