Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Simple For-Each question ... but not for me ...

I'm trying to perform some code against two small ranges, but it's not
working .... here's the first line of the code:
For Each r In Worksheets("ADMIN").Range("c16:c34", "I16:I33")

When I run the code, it runs the actions against ALL cells in range
C16:I33!

What am I doing wrong?

TIA,
ray

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Simple For-Each question ... but not for me ...

You might try:

For Each r In
UNION(Worksheets("ADMIN").Range("c16:c34"),Workshe ets("ADMIN").Range("I16:I33"))

AFAIK, Range(Cell1,Cell2) syntax is generally used to specify start (Cell1)
& end (Cell2) points of a single contiguous range. Since you fed it multiple
cells rather than the single cell arguments it expected, Excel simply
constructed a Range based on the topleft cell of Cell1 and the bottomright
cell of Cell2, resulting in C16:I33.

HTH,


"Ray" wrote in message
ps.com...
I'm trying to perform some code against two small ranges, but it's not
working .... here's the first line of the code:
For Each r In Worksheets("ADMIN").Range("c16:c34", "I16:I33")

When I run the code, it runs the actions against ALL cells in range
C16:I33!

What am I doing wrong?

TIA,
ray



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Simple For-Each question ... but not for me ...

try it this way:

With Worksheets("ADMIN")
For Each r In Union(.Range("C16:C34"), .Range("I16:I33"))
'your code here
Next r
End With


--
Hope that helps.

Vergel Adriano


"Ray" wrote:

I'm trying to perform some code against two small ranges, but it's not
working .... here's the first line of the code:
For Each r In Worksheets("ADMIN").Range("c16:c34", "I16:I33")

When I run the code, it runs the actions against ALL cells in range
C16:I33!

What am I doing wrong?

TIA,
ray


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Simple For-Each question ... but not for me ...

Try a union instead of a range

Sub test1()

With Worksheets("ADMIN")
For Each r In Union(.Range("c16:c34"), .Range("I16:I33"))

Next r
End With
End Sub
"Ray" wrote:

I'm trying to perform some code against two small ranges, but it's not
working .... here's the first line of the code:
For Each r In Worksheets("ADMIN").Range("c16:c34", "I16:I33")

When I run the code, it runs the actions against ALL cells in range
C16:I33!

What am I doing wrong?

TIA,
ray


  #5   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Simple For-Each question ... but not for me ...

Thanks George .... that did the trick! And I also appreciate the tip
on specifying ranges -- good to know!

Regards,
ray



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
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
simple question A.G.M ash[_2_] Excel Programming 3 January 28th 07 10:21 AM
Simple VBA question (?) Kees Korver[_4_] Excel Programming 1 July 4th 06 09:26 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM


All times are GMT +1. The time now is 10:11 PM.

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

About Us

"It's about Microsoft Excel"