Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Set MyRange for non-adjacent cells and iterate through?

What I have in mind to try and do would be easy if I could iterate through
all the cells of a specified block of cells, picking out certain cells that
meet a specific criterion, and adding them to MyRange object. These cells
would probably be scattered over the original block of cells and many would
not be adjacent to any other cell in MyRange. Then I would iterate through
all the cells in MyRange to do things, and drop cells out of MyRange until I
have exactly what I want. Is it possible to set up a range of non-adjacent
cells so they can be iterated through? If so, what's the easiest methods to
use to add or delete a cell from such a range?

Thank you.
Ed


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Set MyRange for non-adjacent cells and iterate through?

One way...

dim myRng as range
dim myCell as range
dim mySubsetRng as range

set myrng = activesheet.range("a1:c9")
for each mycell in myrng.cells
if mycell.value = lcase(mycell.value) then
if mysubsetrng is nothing then
set mysubsetrng = mycell
else
set mysubsetrng = union(mysubsetrng,mycell)
end if
end if
next mycell

for each mycell in mysubsetrng.cells
msgbox mycell.value & vblf & mycell.address
next mycell



Ed wrote:

What I have in mind to try and do would be easy if I could iterate through
all the cells of a specified block of cells, picking out certain cells that
meet a specific criterion, and adding them to MyRange object. These cells
would probably be scattered over the original block of cells and many would
not be adjacent to any other cell in MyRange. Then I would iterate through
all the cells in MyRange to do things, and drop cells out of MyRange until I
have exactly what I want. Is it possible to set up a range of non-adjacent
cells so they can be iterated through? If so, what's the easiest methods to
use to add or delete a cell from such a range?

Thank you.
Ed


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Set MyRange for non-adjacent cells and iterate through?

Thank you, Dave! It works great!

Ed

"Dave Peterson" wrote in message
...
One way...

dim myRng as range
dim myCell as range
dim mySubsetRng as range

set myrng = activesheet.range("a1:c9")
for each mycell in myrng.cells
if mycell.value = lcase(mycell.value) then
if mysubsetrng is nothing then
set mysubsetrng = mycell
else
set mysubsetrng = union(mysubsetrng,mycell)
end if
end if
next mycell

for each mycell in mysubsetrng.cells
msgbox mycell.value & vblf & mycell.address
next mycell



Ed wrote:

What I have in mind to try and do would be easy if I could iterate

through
all the cells of a specified block of cells, picking out certain cells

that
meet a specific criterion, and adding them to MyRange object. These

cells
would probably be scattered over the original block of cells and many

would
not be adjacent to any other cell in MyRange. Then I would iterate

through
all the cells in MyRange to do things, and drop cells out of MyRange

until I
have exactly what I want. Is it possible to set up a range of

non-adjacent
cells so they can be iterated through? If so, what's the easiest

methods to
use to add or delete a cell from such a range?

Thank you.
Ed


--

Dave Peterson



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
compare 2 column cells and return the adjacent columns cells data of the cell trebor57 Excel Worksheet Functions 1 February 1st 11 02:54 PM
Add cells on two adjacent rows but non-adjacent columns Eve Excel Worksheet Functions 14 October 20th 09 02:32 AM
Why Copy/Paste fails using Offset & Resize of myRange? [email protected] Excel Discussion (Misc queries) 3 November 21st 06 02:06 AM
Help ASAP myRange VBA[_2_] Excel Programming 0 November 15th 04 10:33 PM
How To Iterate a range of cells? StarGazerNC Excel Programming 5 August 4th 04 04:51 PM


All times are GMT +1. The time now is 08:35 PM.

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"