Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For Each in Range


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


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile: http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=377159

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For Each in Range


Perhaps this will help.

Code:
--------------------

Sub Test()
Dim rngRpt As Range
Dim LastRow As Long
Dim c As Range
Dim I As Long
Set rngRpt = Range("B1", Range("IV1").End(xlToRight))
LastRow = Range("A65536").End(xlUp).Row

For Each c In rngRpt
For I = 2 To LastRow
If Cells(I, c.Column) = "X" Then
MsgBox Range("A" & I) & "-" & Cells(1, c.Column)
End If
Next I
Next c
End Sub
--------------------

I haven't included any code to actually add to the mailing list as I
don't know what method you are using for that.


--
Norie
------------------------------------------------------------------------
Norie's Profile: http://www.excelforum.com/member.php...o&userid=19362
View this thread: http://www.excelforum.com/showthread...hreadid=377159

  #3   Report Post  
Posted to microsoft.public.excel.programming
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For Each in Range


Different approaches, both good answers.

Thanks to both of you for your help. I get confused (all too often)
when it comes to dealing with Range.

Thanks Again!


DejaVu


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile: http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=377159

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I enter formula sum(range+range)*0.15 sumif(range=3) tkw Excel Discussion (Misc queries) 2 October 1st 09 09:17 PM
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Range.Find returns cell outside of range when range set to single cell Frank Jones Excel Programming 12 June 10th 04 04:22 AM
how to? set my range= my UDF argument (range vs. value in range) [advanced?] Keith R[_3_] Excel Programming 2 August 11th 03 05:55 PM


All times are GMT +1. The time now is 10:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"