Steve,
When all else fails "read the directions".
The range returned by the Intersection method is whatever Excel
interprets it to be. So it is best to specify what you want...
Set rng = Application.Intersect(rng1, rng2).Cells
Set rng = Application.Intersect(rng1, rng2).Columns
Set rng = Application.Intersect(rng1, rng2).Rows
The UsedRange size varies and is not immune from the false
right or bottom issue.
Excel Range? Not clear what you mean.
Is Nothing is either True or False, so...
Not False = True
Not True = False
The "Target" could be any size range, depending on what the user
selected or changed, so Target.Cells returns the "Cells" in the Target.
Target.Cells(1, 1) is the top left cell. (of one or more cells)
Target.Cells(2, 1) in most cases would be valid, though it could be
outside of the Target range. (think about that one).
It would be invalid if Target.Cells(2, 1) fell off of the worksheet.
I know I said read the directions, but in the case of "Me", it is not much
help. When used in the module behind (belonging to) a sheet it refers to
that sheet. When used in the module belonging to a UserForm it refers
to the Form. In most other instances, using it will throw an error.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
I do tons of "OnEntry" checking in applications and I'm always looking for
ways to NOT hard code stuff so this is very interesting.
<<<< Application.Intersect(Rows(2), ActiveSheet.UsedRange)
Can I assume that the inverse
Application.Intersect(Columns("B"), ActiveSheet.UsedRange)
would yield ROWS
is "UsedRange" immune from the false "right" or "bottom" that "xlbottom"
issue that doesn't seem to go away after rows/columns are cleared/deleted.
It is also useful in Worksheet events to determine if a changed cell
falls within a specified range...
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Me.Columns("B"), Target.Cells(1, 1)) Is
Nothing Then
I've got only a 2 fingered grip on this one and need to run some permatation
questions of an image I'm trying to form. I can see that some of the answers
may be a "well dah" but I just want make sure.
"ExcelRange" = cell or cells touched before press of ENTER (cells perhaps
for a format change, or copy of a range.
Double negatives spin my head but how's this "If it's not nothing then
something was touched"
can I assume that "Target.cells(1,1)" means there always must be an upper
left cell even in a range of one cell.
In your example are we checking the top row in what could be a range that is
only one cell wide
And if yes, would the "1" in Target.cells(1,1) ever have a different value
If the range was more than one cell then Target.cells(2,1) could be valid.
and based on you having used Me.Columns("B") does than mean
Target.cells(1,2) would be invalid.
Is there magic in your use of "ME." as "ME" being a magic word in Excel. I
realize that your example would have ultimately come from within lots more
code where you may have just done "SET ME as (some kind of object). or
there a default ME. for object that just exist without being formerly
declared. (I think I misremember something like that in UserForms)
Thanks for wading through this.
Steve Moland