Excel VB Looping and e-mailinh

cnugent

New Member
Joined
Jan 10, 2011
Messages
14
I have a file that I need to send to a group of individuals, however each person only sees certain parts of the file. I need help with two parts of this macro.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I created macros that will hide the sheets that aren't needed for the individuals so that when it is finished the only thing visible is what pertains to that individual. The one part of the macro I am missing is how to email it to this individual when the tweaking part of the macro is done. The email is based on a temporary tab containing their emails and based on how I set up the tweaking of the files it will always be in H2.<o:p></o:p>
<o:p></o:p>
The second part I am missing is a statement that says when the email is sent delete that person from the temp list and go back to the top of the script and do all the filters over again with the second person on the list. I know this is a loop, but I am unfamiliar with loops and heard they can be dangerous t create so I thought I'd ask. When the temporary tab of emails is empty (except for the header on top) I want the loop to stop.<o:p></o:p>
<o:p></o:p>
I'm sure to you experts this should be a breeze, but I don't know where to begin.<o:p></o:p>
<o:p></o:p>
Thanks in Advance for your help<o:p></o:p>
<o:p></o:p>
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
The Loop would look something like:

Code:
Option Explicit
Dim wb As Workbook
Dim ws As Worksheet
Dim i As Long

Set wb = Activeworkbook
Set ws = wb.Sheets("Email Tab Name")

'Assuming that Your emails start in A2 (A1 being the header)-

For i = 2 To ws.Columns(1).Find("*", SearchDirection:=x;Previous).Row
'Info Sheet Formatting Code Here
'Emailing Code Here
'Send Email to
ws.Cells(i,1).Value
Next i

There's no need to worry about deleting the emails unless you really want to.

What programme will you be using for the emailing? Outlook, groupwise......?
 
Last edited:
Upvote 0
Re: Excel VB Looping and e-mailing

Thanks for the quick reply.

I hope this info will give the information we need to finzlize this macro.

I am using outlook to send the email.

The subject line is going to be called "weekly comparison"

The body of the messsage is "here is your weekly comparison"

The email address is actually is H2, Not A2

the reason i want to delete it is that once it deletes the row the way I have the macro is that it will than take the next value on the list and run all the calculations on it...theres a lot of code above that I know could have been written better, but as you can tell I'm not that good at this. So as I fix I just need to delete that row (since it's on a temporary sheet just for that purpose) and than go back to the top of the code once the emai is sent- which i don't know how to do that either

I think I'm in over my head

Thanks for your help
 
Upvote 0
In that case the loop will be updated ever so slightly:

Code:
Option Explicit
Dim wb As Workbook
Dim ws As Worksheet
Dim i As Long

Set wb = Activeworkbook
Set ws = wb.Sheets("Email Tab Name")

'Assuming that Your emails start in A2 on the Temporary Tab(A1 being the header)-

For i = ws.Columns(1).Find("*", SearchDirection:=x;Previous).Row To 2 Step -1 
'Info Sheet Formatting Code Here
'Emailing Code Here
'After Sending email Delete Address from List
ws.Cells(i,1).ClearContents
Next i

When deleting items from a Loop it's best to Loop in reverse so start at the last item in the list and finish on the first.

This link contains lots of info about coding the email part: http://www.rondebruin.nl/sendmail.htm
 
Upvote 0

Forum statistics

Threads
1,224,617
Messages
6,179,914
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top