View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default For Each in Range

One way:

Dim rCell As Range
Dim MailToList As Collection
Set MailToList = New Collection
For Each rCell In Cells(2, 2).Resize( _
Cells(Rows.Count, 1).End(xlUp).Row - 1, _
Cells(1, Columns.Count).End(xlToLeft).Column - 1)
If UCase(rCell.Text) = "X" Then
On Error Resume Next
MailToList.Add Cells(rCell.Row, 1).Text, _
Cells(rCell.Row, 1).Text
On Error GoTo 0
End If
Next rCell




In article ,
DejaVu wrote:

I'm working on some code that will add names to a Mail To list.
I have a worksheet that looks like the following (ignore the
underscores):

________Report 1___Report 2___Report 3___Report 4
Bill_________X________X
Joe________X__________________X
Jim__________________X________X
Bob________X__________________X_________X

I set my all of my reports to a range, and my people to a range.
Set RptRng = Range("B1", Selection.End(xlToRight))
Set MailRng = Range("A2", Selection.End(xlDown))

I'm trying to do some sort of:
For Each Report in RptRng
If ________ = "X" then
add Person to MailToList

I hope my explanation is good enough! Any help is greatly
appreciated!

DejaVu