Thread: Range Question
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
theDude[_10_] theDude[_10_] is offline
external usenet poster
 
Posts: 1
Default Range Question


This code should work for you. It will dynamically determine the number
of reports and recipients, so if you add more reports and/or recipients
to the matrix you won't have to change the macro code. Please delete
the code line in *BOLD* below after you have tested it to ensure it
works for you:

Code:
--------------------
Sub sendReports()
Dim repCount As Integer, nameCount As Integer
Dim x As Integer, y As Integer
Dim MailTo As String

' Determine number of reports to send...
repCount = ActiveSheet.UsedRange.Columns.Count
' Determine number of names to send reports to...
nameCount = ActiveSheet.UsedRange.Rows.Count

' Initialize variable...
MailTo = ""

' Loop through report recipient matrix & send reports...
For x = 2 To repCount ' Skip 1 for name column
For y = 2 To nameCount ' Skip 1 for header row
' Determine if report should be sent to recipient...
If ActiveSheet.Cells(x, y) = "X" Then
' If true, update variable with recipient name & comma separator w/trailing space...
MailTo = MailTo & ActiveSheet.Cells(y, 1) & ", "
End If
Next y
' Strip last comma separator from variable...
MailTo = Left(MailTo, Len(MailTo) - 2)
*MsgBox "E-Mail " & ActiveSheet.Cells(1, x).Value & " to: " & MailTo*

'********** YOUR CODE TO E-MAIL REPORT GOES HERE **********

' Clear variable for next report...
MailTo = ""
' Loop to next column to get report recipients...
Next x
End Sub
--------------------

Hope this helps,
theDude


--
theDude
------------------------------------------------------------------------
theDude's Profile: http://www.excelforum.com/member.php...o&userid=16550
View this thread: http://www.excelforum.com/showthread...hreadid=377095