+ Reply to Thread
Results 1 to 42 of 42

Email lines based on column value

  1. #1
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Email lines based on column value

    This is my first post so I hope I have the protocol etc correct ....

    I am administering an event that about 30 people are attending. I'm accepting scores of payments each month from various sources, each payment assigned to a specific participant.

    I have a Workbook with two Worksheets, Participants and Payments. I export details of all the payments into the latter.

    I want to be able, for each row in Participants, send the participant all the rows in Payments that relate to him/her.

    So in the example, I want to email to Tony Woodcock at a at b.com rows 1 and 4 from the Payments sheet; and to Amelia Earhart rows 2 and 3 (preferable all with a standard wrapper explaining what it all is).

    Is this possible in Excel (or anything else?!).

    All inspiration gratefully accepted.

    Thanks
    N
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Have a look at the attached file. You will see that I have added a header column in row 1 of the Payments sheet. This row is necessary in order to filter the data properly. Change the headers to suit your needs. In the macro located in Module1, change the "Subject" of the email to suit your needs before running the macro.
    Attached Files Attached Files
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    This is fantastic! Thank you!

    Can you indulge me with a couple of follow-up questions? Presumably I can try to learn a bit of VBA programming to a) learn how to omit some columns and b) produce a total at the bottom?

    And, this creates 30 emails within Outlook for me to press SEND on - no way of by-passing the need to do that?

    cheers
    N

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Regarding your questions, I'm not sure if you are asking for help to do what you described in the file that you posted.
    To avoid having to press SEND for each email, just change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    in the code.

  5. #5
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    Regarding your questions, I'm not sure if you are asking for help to do what you described in the file that you posted.
    Hi Mumps1. I have a few more things to iron out which I am struggling with, hence the questions:

    1. The sample workbook which I provided, into which you so kindly inserted the macro, was a slightly simplified version of the one I actually have. I am having problems adapting the macro in the sample file to make it work with the actual one, which has a couple more columns.
    2. I'm also quite confused about how to copy a macro from one worksheet to another.
    3. I only want to display some, not all, columns in the email.
    4. Finally, I'd like to present a total of the lines on each statement.


    Small things and if I spend long enough I may be able to work them out for myself.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    When a macro is designed, it is based on the available data. Any change in the data or in the way it is organized, will create confusion for the macro. A macro that works with a sample file most often will not work on an actual file. If you could post a copy of your actual file (de-sensitized if necessary) and explain in detail what you want to do, I can have another look at it.

  7. #7
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    When a macro is designed, it is based on the available data. Any change in the data or in the way it is organized, will create confusion for the macro. A macro that works with a sample file most often will not work on an actual file. If you could post a copy of your actual file (de-sensitized if necessary) and explain in detail what you want to do, I can have another look at it.
    Hi Mumps1. Real file but anonymised file attached. I am so grateful for your help. It's a charity event so you are doing Good Works

    Pretty much as per your previous macro I'd like to, for each participant (other than 999), create an email listing each of his/her payments and if possible a total at the bottom. I only want columns Date, Description and Amount from the payments worksheet.

    Thanks again
    N
    Attached Files Attached Files

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    In the file you posted, column B in the Participants sheet has only one name (John), repeated multiple times. Can I assume that column B in the Participants sheet should have a list of many unique different names? If this is true, please post an updated file with column B in the Participants sheet containing the unique names.

  9. #9
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    In the file you posted, column B in the Participants sheet has only one name (John), repeated multiple times. Can I assume that column B in the Participants sheet should have a list of many unique different names? If this is true, please post an updated file with column B in the Participants sheet containing the unique names.
    Yes that's right. Column B can have many different name, but they won't necessarily be unique - every chance there would be two Johns for example.
    Interested to know why this matters though, as the link between the worksheets is on the reference number, eg 405.
    Updated sheet attached.
    Thanks!
    N
    Attached Files Attached Files

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    If we use Charlie as an example, does that mean that he would get two separate emails, one based on Ref# 463 and another based on Ref# 660? This would result in 10 rows of data from the Payments sheet in one email and 8 rows of data from the Payments sheet in the other email. Or do you want one email for Charlie that includes both Ref numbers?

  11. #11
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    If we use Charlie as an example, does that mean that he would get two separate emails, one based on Ref# 463 and another based on Ref# 660? This would result in 10 rows of data from the Payments sheet in one email and 8 rows of data from the Payments sheet in the other email. Or do you want one email for Charlie that includes both Ref numbers?
    No. 463 isn't really called Charlie Vestey, and 660 isn't called Charlie Vestey either. The references (463, 600 etc are unique identifiers of one and only one person. The fake first and surnames I have assigned are completely immaterial.

    Shall I redo the sample?

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Please post a sample that is exactly representative of your data. As I mentioned earlier, we can design a macro based only the data you post.

  13. #13
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Here you go.
    Attached Files Attached Files

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Just to confirm: some of the names can be repeated more than once and each occurrence of the name will always have the same Ref number in column A of the Participants sheet. Is this correct?

  15. #15
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    Just to confirm: some of the names can be repeated more than once and each occurrence of the name will always have the same Ref number in column A of the Participants sheet. Is this correct?
    It's possible that there could be several Johns, and there could be several Smiths, and there could even be several John Smiths. But they would all be different people. The Ref in Column A uniquely identifies one and only one person.

  16. #16
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    Just to confirm: some of the names can be repeated more than once and each occurrence of the name will always have the same Ref number in column A of the Participants sheet. Is this correct?
    Is there any more info I can provide to help? So grateful for the help so far - I'm 90% there!
    Thanks
    N

  17. #17
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Try:
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Thanks!
    It failed with an error, see attached.
    I'll try and work it out myself but if it's obvious please do shout! ;-)
    Thanks
    N
    Attached Images Attached Images

  19. #19
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    I tested the macro on the file you posted and it worked properly. Are you using the macro in the same file or in a different file? If in a different file, please post a copy of the file that is generating the error.

  20. #20
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22
    Quote Originally Posted by Mumps1 View Post
    I tested the macro on the file you posted and it worked properly. Are you using the macro in the same file or in a different file? If in a different file, please post a copy of the file that is generating the error.
    No, I popped it into the WSJ Anonymised v0.3 file which I uploaded a couple of days ago by using Macros->Create-> then cut and pasted your suggestion. I think!

  21. #21
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Because I cannot reproduce the error, it is difficult to find the problem. Could you post a copy of the file that is generating the error and I will try again?

  22. #22
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    Because I cannot reproduce the error, it is difficult to find the problem. Could you post a copy of the file that is generating the error and I will try again?

    Hi. Thanks for persevering! I downloaded my WSJ Anonymised v0.3 file, posted on 06/08/22 to make sure I had the exact version, and pasted the macro you uploaded on 10/08/22. It comes up with the same error. Here I post WSJ Anonymised v0.4, which contains your macro.

    Thanks
    N
    Attached Files Attached Files

  23. #23
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Try replacing this line of code:
    Please Login or Register  to view this content.
    with this one:
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Thanks, but it still fails:
    Attachment 791887
    Attached Files Attached Files

  25. #25
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Try this line:
    Please Login or Register  to view this content.

  26. #26
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Same error. Here's the file with that change made.
    Attached Files Attached Files

  27. #27
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Try formatting column I in the Payments sheet as 'Number' with no decimal places and try this line of code again:
    Please Login or Register  to view this content.

  28. #28
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    Try formatting column I in the Payments sheet as 'Number' with no decimal places and try this line of code again:
    Please Login or Register  to view this content.
    Sadly, same result.

  29. #29
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    I may have found the problem. In the Payments sheet you have a filter drop down arrow in cell H2. This is confusing the autofilter in the macro. Try this version with your original file. It removes that filter drop down arrow in cell H2 before executing.
    Please Login or Register  to view this content.

  30. #30
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Yes, that's it! In fact removing the filter and running any of the recent versions works fine now. Thank you so much!

    I'm furiously trying to learn VBA so I can maintain this. Would you mind explaining briefly what this line is doing?:
    With paySH
    .Range("A1").AutoFilter 9, v(i, 1)


    Finally, is there an easy way to run the macro so that it addresses just one or some rows in the Participants sheet, rather than all? Doesn't really matter if not, I can cancel them in Outlook.

    Thanks Again!

  31. #31
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    The variable 'v' holds all the values in column A of Participants. v(i,1) represent the first value in column A and it is used to filter column I in the Payments sheet so that only the relevant rows are visible. As the value of 'i' is increased in the loop, the macro processes the next row.
    is there an easy way to run the macro so that it addresses just one or some rows in the Participants sheet, rather than all?
    If there is a way of identifying which particular rows the macro will process, then that would be possible. If not, the macro has no way of knowing which rows you want to process.

  32. #32
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Quote Originally Posted by Mumps1 View Post
    The variable 'v' holds all the values in column A of Participants. v(i,1) represent the first value in column A and it is used to filter column I in the Payments sheet so that only the relevant rows are visible. As the value of 'i' is increased in the loop, the macro processes the next row.
    If there is a way of identifying which particular rows the macro will process, then that would be possible. If not, the macro has no way of knowing which rows you want to process.
    I could include a new row A which would have an 'X' for those I wanted to process, and blank for all the others I suppose. I'll play with that when I am better at VBA.

    Thanks again!

  33. #33
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    If you upload a revised file with the X's, I'll have a look.

  34. #34
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Here's v0.4 again, with an X in the first column. (Would it have been easier to make it the last?)
    Attached Files Attached Files

  35. #35
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    Try:
    Please Login or Register  to view this content.

  36. #36
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Thanks. It doesn't quite work but I'll try to work it out myself.

  37. #37
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    I forgot to mention that you will need to insert a header row in row 1 in the Participants sheet.

  38. #38
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    That works beautifully!

  39. #39
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    I'm using it in anger now!

    Ideally the total would be to decimal places. Currently it looks like this:
    TOTAL: 1549.5

    (rather than TOTAL: 1549.50).

    Do you know why Outlook is not displaying my signature, as it does when I create a manual mail?

    Thanks!

  40. #40
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    This should take care of the TOTAL formatting:
    Please Login or Register  to view this content.
    Have a look at this link regarding the signature: https://www.rondebruin.nl/win/s1/outlook/signature.htm

  41. #41
    Registered User
    Join Date
    08-03-2022
    Location
    England
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2206 Build 16.0.15330.20216) 64-bit
    Posts
    22

    Re: Email lines based on column value

    Run Time Error:13 Type Mismatch
    tot = tot + x

  42. #42
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Email lines based on column value

    I'm not getting the error. Are you still using the macro on the same file? Is the filter drop down arrow still there in H2 of Payments?

+ 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] Need help summing lines based on ID in another column and changing dates
    By maym in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-22-2021, 08:01 PM
  2. [SOLVED] pull email address from a column based on criteria from another column
    By cinstanl in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2016, 08:09 AM
  3. [SOLVED] inserting two blank lines when based on data in a column
    By El Conquistador in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-08-2013, 02:05 PM
  4. How do i select lines based on value in one Column and copy to other Workbook
    By dappelma in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-18-2013, 05:38 PM
  5. Removing blank lines based on first column
    By SWMagic in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2013, 03:31 AM
  6. For each unique value in col A+B, removing lines based on column C
    By smokebreak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-21-2010, 12:38 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