+ Reply to Thread
Results 1 to 2 of 2

send email based on cell value

  1. #1
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    send email based on cell value

    I have this code here:
    Please Login or Register  to view this content.
    I want it to look in the column on sheet("Customer Data") Column (BV) & find the City name. When the email generates then WH as the range from worksheet("Codes").Range(P:V) based on the city value located on worksheets("codes").Column(S). I ran the code but it does not throw an error & outlook does not generate the email. Any help would be greatly appreciated!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,717

    Re: send email based on cell value

    I see a number of problems in your code, but I am not sure which one is keeping your emails from being created.

    I cannot run your code without your file and some sample data. Feel free to attach a file if it does not contain private data.

    Here are the things that need to be fixed:

    What module is this code in? If you have it in a standard module (e.g., Module1) all range references will default to be whatever is the active sheet. You haven't given enough information for me to determine if that's what you want. What sheet do you mean to refer to

    Please Login or Register  to view this content.
    I am sure you think you have declared four String variables. However, you have declared three Variant variables and one String variable. You must specify a data type for each variable when you have multiple variables on the same Dim statement.
    Please Login or Register  to view this content.
    You have not declared BR.

    You set sh
    Please Login or Register  to view this content.
    but you never use it anywhere.

    You are setting your greeting message "Good morning" etc., each time through the loop. You can do this one time before entering the loop, since it's going to be the same greeting for every email.

    You are creating a loop, but referring only one cell. You don't need a loop to do this:
    Please Login or Register  to view this content.
    Your If statements are mutually exclusive--you can only pick one. In such a case I would use a Case statement instead.

    You are setting Warehouse, a String variable, to a range of values. This will not work the way you are expecting. It will only use the first value in the range. Are you trying to create a string that concatenates all the cells from column P to V?

    I think you want something like this:
    Please Login or Register  to view this content.
    You don't need to .Display twice. It's not harmful, but the first one is not useful.
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. Send Email Based on Cell Value
    By M5B in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-13-2018, 02:07 PM
  2. [SOLVED] Send Email Based on Cell Values
    By weeblegobble in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2018, 12:18 AM
  3. Can I have Excel send an email based on cell contents
    By msche09 in forum Excel General
    Replies: 2
    Last Post: 04-09-2014, 03:51 AM
  4. Workflow with signatures (if cell=x then send email, if signed then send email)
    By Kate2811 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2014, 05:37 AM
  5. Send email to address based on cell value
    By shiftyspina in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 03:06 PM
  6. Send email based on address in a cell
    By behnam in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-19-2013, 02:53 PM
  7. send an email based on data in specific cell
    By savage in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2010, 11:54 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