Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default (Reverse Union) Randomly draw address from Range

I am looking to build a function that does the opposite of a union function.
Put it in a loop that randomly draws a cell from a pre-defined range. And
redefine what that range would look like after the draw.

So for example lets say my pre-defined address is A1:Z400. I want the
ability to randomly draw a single cell address (say H60) and then remove this
address from the pre-defined range of A1:Z400 so that it now look like:

A1:G400, H1:H59,H61:H400,I1:Z400.

Now I dont think I will be able to store this string as a range variable as
I think I have limits on the lenght of the string stored in a Range variable
(254 char). So as I continue to draw cells from the range, the concatenated
string will get longer and longer over time and breach the 254 char limit.

Any ideas on how to approach this?

Thanks

EM


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default (Reverse Union) Randomly draw address from Range

I'm not sure how you're going to choose that cell at random, but I'd start here
for "unselecting" a range:

http://www.cpearson.com/excel/unselect.htm
(from Chip Pearson's site)

ExcelMonkey wrote:

I am looking to build a function that does the opposite of a union function.
Put it in a loop that randomly draws a cell from a pre-defined range. And
redefine what that range would look like after the draw.

So for example lets say my pre-defined address is A1:Z400. I want the
ability to randomly draw a single cell address (say H60) and then remove this
address from the pre-defined range of A1:Z400 so that it now look like:

A1:G400, H1:H59,H61:H400,I1:Z400.

Now I dont think I will be able to store this string as a range variable as
I think I have limits on the lenght of the string stored in a Range variable
(254 char). So as I continue to draw cells from the range, the concatenated
string will get longer and longer over time and breach the 254 char limit.

Any ideas on how to approach this?

Thanks

EM


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default (Reverse Union) Randomly draw address from Range

Here's an modification of the last macro.

Sub RngWithExceptions()
Dim rng As Range
Dim rngArea As Range
Dim rngCell As Range
Dim rngUnion As Range
Dim rngException As Range
Set rng = Range("A1:Z100")
Set rngException = Range("H60")
For Each rngCell In rng.Cells
If Intersect(rngCell, rngException) Is Nothing Then
If rngUnion Is Nothing Then
Set rngUnion = rngCell
Else
Set rngUnion = Union(rngUnion, rngCell)
End If
End If
Next
' rngUnion.Select
For Each rngArea In rngUnion.Areas
Debug.Print rngArea.Address(0, 0, , True)
Next
End Sub

Now I dont think I will be able to store this string as a range variable
as
I think I have limits on the lenght of the string stored in a Range
variable
(254 char). So as I continue to draw cells from the range, the
concatenated
string will get longer and longer over time and breach the 254 char limit.


I would not do it this way, one of the reasons being the limitation you see.
I can't think of a time I have ever concatenated ranges this way, so there
must be a different approach available. However, if you are hell bent on
doing this, you could write a macro, I suppose, that stores your exceptions
in a sheet cell by cell, or area by area with each exception, then loop
through them, create a rngUnionExceptions by unioning them, then refer to
the union exceptions rather than the hardcoded one.

--
Tim Zych
SF, CA

"ExcelMonkey" wrote in message
...
I am looking to build a function that does the opposite of a union
function.
Put it in a loop that randomly draws a cell from a pre-defined range. And
redefine what that range would look like after the draw.

So for example lets say my pre-defined address is A1:Z400. I want the
ability to randomly draw a single cell address (say H60) and then remove
this
address from the pre-defined range of A1:Z400 so that it now look like:

A1:G400, H1:H59,H61:H400,I1:Z400.

Now I dont think I will be able to store this string as a range variable
as
I think I have limits on the lenght of the string stored in a Range
variable
(254 char). So as I continue to draw cells from the range, the
concatenated
string will get longer and longer over time and breach the 254 char limit.

Any ideas on how to approach this?

Thanks

EM




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default (Reverse Union) Randomly draw address from Range

Thanks again Tim, you have been stellar at returning posts. I am actually
going somewhere with all of this. I will try to create the random draw and
then follow up with a follow-up question.

Regards

EM



"Tim Zych" wrote:

Here's an modification of the last macro.

Sub RngWithExceptions()
Dim rng As Range
Dim rngArea As Range
Dim rngCell As Range
Dim rngUnion As Range
Dim rngException As Range
Set rng = Range("A1:Z100")
Set rngException = Range("H60")
For Each rngCell In rng.Cells
If Intersect(rngCell, rngException) Is Nothing Then
If rngUnion Is Nothing Then
Set rngUnion = rngCell
Else
Set rngUnion = Union(rngUnion, rngCell)
End If
End If
Next
' rngUnion.Select
For Each rngArea In rngUnion.Areas
Debug.Print rngArea.Address(0, 0, , True)
Next
End Sub

Now I dont think I will be able to store this string as a range variable
as
I think I have limits on the lenght of the string stored in a Range
variable
(254 char). So as I continue to draw cells from the range, the
concatenated
string will get longer and longer over time and breach the 254 char limit.


I would not do it this way, one of the reasons being the limitation you see.
I can't think of a time I have ever concatenated ranges this way, so there
must be a different approach available. However, if you are hell bent on
doing this, you could write a macro, I suppose, that stores your exceptions
in a sheet cell by cell, or area by area with each exception, then loop
through them, create a rngUnionExceptions by unioning them, then refer to
the union exceptions rather than the hardcoded one.

--
Tim Zych
SF, CA

"ExcelMonkey" wrote in message
...
I am looking to build a function that does the opposite of a union
function.
Put it in a loop that randomly draws a cell from a pre-defined range. And
redefine what that range would look like after the draw.

So for example lets say my pre-defined address is A1:Z400. I want the
ability to randomly draw a single cell address (say H60) and then remove
this
address from the pre-defined range of A1:Z400 so that it now look like:

A1:G400, H1:H59,H61:H400,I1:Z400.

Now I dont think I will be able to store this string as a range variable
as
I think I have limits on the lenght of the string stored in a Range
variable
(254 char). So as I continue to draw cells from the range, the
concatenated
string will get longer and longer over time and breach the 254 char limit.

Any ideas on how to approach this?

Thanks

EM





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
can i put in numbers and have the computer randomly draw 1?how? Slopez Excel Worksheet Functions 1 January 25th 08 05:10 PM
union range Curt Excel Discussion (Misc queries) 9 April 20th 07 02:32 PM
union range problem Walter Excel Programming 2 May 13th 06 12:28 AM
Union/Range/Cells KentÄ[_3_] Excel Programming 2 March 11th 05 11:14 AM
Union method for Range Object Chad Excel Programming 5 March 10th 05 08:02 PM


All times are GMT +1. The time now is 01:28 AM.

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"