+ Reply to Thread
Results 1 to 18 of 18

Reference a cell in a different sheet to send email

  1. #1
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Reference a cell in a different sheet to send email

    I Have some VBA code to save a sheet as a pdf and then email it out, what i would like to know is how can i reference a cell on a different sheet on the same wrokbook to reference the email address


    i thought of using

    Please Login or Register  to view this content.
    but it didnt work

    any ideas on what i can use?

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Reference a cell in a different sheet to send email

    If more than one workbook is open, make sure you're referencing the right one:
    Please Login or Register  to view this content.
    Last edited by leelnich; 02-22-2018 at 03:12 PM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  3. #3
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    hi thanks for the reply


    ive tried your suggestions, and the VBA runs without errors but the email address field remains empty

    is there something im missing, should they be in quotation marks?

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Reference a cell in a different sheet to send email

    I just realized you're missing quotes in your range address:
    Please Login or Register  to view this content.
    Do you have an On Error Resume Next statement in effect? Because that should have errored!
    Last edited by leelnich; 02-22-2018 at 06:19 PM.

  5. #5
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    awesome, cheers dude

  6. #6
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    How do i reference a alarger range,

    ie A2:A20, do they need to be in quotations?

  7. #7
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Reference a cell in a different sheet to send email

    Yes, the argument may be a string, or another range object. Here' s a method for finding all used cells in column A:
    Please Login or Register  to view this content.
    http://www.excel-easy.com/vba/range-object.html
    Last edited by leelnich; 02-22-2018 at 06:28 PM.

  8. #8
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    Cheers

    How would i reference that


    would it be something like this

    Please Login or Register  to view this content.

  9. #9
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Reference a cell in a different sheet to send email

    Actually, setting an object variable = to a range includes the Parent Objects of that range. So, again make sure your referencing the right workbook/worksheet when defining MyRange. Otherwise it assumes ActiveWorkbook.ActiveSheet.
    Please Login or Register  to view this content.
    Notice the periods leading "Range", "Cells", and "Rows". They indicate the object is a "member" of the With Object.
    Last edited by leelnich; 02-22-2018 at 07:01 PM.

  10. #10
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    WOW that looks a little above my current understanding of VBA

    Please Login or Register  to view this content.

    here is my code , would it be possible to add your code to it please, im a little unsure where it will go

  11. #11
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Reference a cell in a different sheet to send email

    That's just a snippet that demos using a loop to take some particular action on a bunch of cells. It doesn't appear to apply to your specific macro. Where in your code are you trying to reference a multi-cell range?

  12. #12
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    Please Login or Register  to view this content.

    thank you

  13. #13
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Reference a cell in a different sheet to send email

    Ok, you're trying to send the same email to a bunch of people, so you need to build a recipient list - a text string with addresses separated by ";". VBA's Join function is perfect for this. It takes an array of values - from a cell range in this case - and joins them using a specified delimiter. It's a little arcane, because Excel ranges are 2-dimensional arrays (rows AND columns), while Join needs a 1-dimensional array (row). So we have to use Excel's Transpose function to convert our column range into a row array. See below:
    Please Login or Register  to view this content.
    Alternatively, you could loop through the range as the demo did, appending ";" and an address to the end of a string on each pass. But that's slower.
    Last edited by leelnich; 02-22-2018 at 08:27 PM.

  14. #14
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    Thank you

    in terms of this line
    Please Login or Register  to view this content.
    i thought it would have been something like this

    Please Login or Register  to view this content.
    Last edited by kobiashi; 02-22-2018 at 09:05 PM.

  15. #15
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Reference a cell in a different sheet to send email

    Sorry, you are correct. Assuming sheet "email" is part of the ActiveWorkbook, your changes should work as shown. Nice catch!

  16. #16
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    I've added it but it came up with a run time error 9, am i missing something

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    08-22-2016
    Location
    london
    MS-Off Ver
    2013
    Posts
    121

    Re: Reference a cell in a different sheet to send email

    Cancel that, its working


    thank you for your help

  18. #18
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Reference a cell in a different sheet to send email

    You're welcome!

+ 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. Condition on sendint email or not to send email by a yes no in a cell
    By toofani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2015, 04:35 AM
  2. 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
  3. How to send email from excel using VBA with Cell Range (Including Images) as Email Body
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2014, 05:06 AM
  4. Using VBA to send Email by selecting email from a cell within a worksheet
    By sm.salford in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-17-2013, 01:58 PM
  5. Auto send email with the cell value that triggered the email in the first place.
    By coobey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-02-2013, 05:40 PM
  6. [SOLVED] Send Email 1 sheet as attachment and other sheet as body of emial.
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-19-2013, 02:57 AM
  7. Replies: 2
    Last Post: 07-31-2012, 10:00 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