can u explain this line for me?

  • Thread starter Thread starter serdar
  • Start date Start date
S

serdar

i am unfamiliar with vbasic syntax..so what is
Intersect( )
and
Is Nothing?


--If Not Intersect(Target, Me.[a1]) Is Nothing
 
Take a look at the Intersect Method in VBA Help.

Is Nothing means that an object variable (or the result of a method that
returns an object) is not associated with an object.
 
Hi serdar,

Intersect() is a VBA function which returns a range which is the
intersection between the ranges used as arguments in this functions. If the
ranges evaluated do not intersect then Intersect() returns Nothing.

In the specific example Target is the variable for the range being modified
(which triggers the Change event of the Worksheet). It can be one or
multiple cells. Normally, you modify one cell at a time so Target would
return a one cell range in most of the cases, however it will return a
multi-cell range if you copy-paste multiple cells, etc.

Me is the short way of referring to the object in whose VBA module the macro
is. In this particular case Me refers to the worksheet which we are
monitoring for changes.

[A1] is the range that we actually monitor as we don't care about the rest
of the cells on this sheet.

So Intersect(Target, Me.[a1]) is trying to determine the range which is the
intersection of the range being changed and the range we are monitoring.
This will be the case if A1 is one of the cells changed. If A1 is not being
changed in this particular event, Intersect(Target, Me.[a1]) will return
Nothing, which is what we are trying to trap with the If...Then construct.

The Not operator changes boolean result (TRUE/FALSE) to its opposite, so the
statement "Not Intersect(Target, Me.[a1]) Is Nothing" actually means:

Intersect(Target, Me.[a1]) Is NOT Nothing

Therefore the statement "If Not Intersect(Target, Me.[a1]) Is Nothing Then
...." means: if the intersection between the 'range changed' and A1 is not
nothing (is a range), then proceed with the following action (otherwise do
nothing).

Hope this helps,

Regards,
KL
 
I think, in the case you're citing:

Target is the default argument for some events (like the Worksheet_Change
event)

Me refers to the parent of the code (probably the worksheet)

Intersect returns cells that are common to two ranges (the overlapping
area). If there is no overlap, then the function returns Nothing, the object
equivalent of Null.

Given the above:
If Not Intersect(Target, Me.[a1]) Is Nothing
Means if the cells that were selected when the worksheet was changed and
cell A1 on that sheet intersect then....do whatever the conditional VBA code
indicates.

Does that help?
 
Thank u for your detailed explanation. I send the current version of my code
as a new thread in this newsgroup, take a look if u like. Any suggestions on
error handling, undoing etc. will be appreciated.






haber iletisinde þunlarý said:
Hi serdar,

Intersect() is a VBA function which returns a range which is the
intersection between the ranges used as arguments in this functions. If the
ranges evaluated do not intersect then Intersect() returns Nothing.

In the specific example Target is the variable for the range being modified
(which triggers the Change event of the Worksheet). It can be one or
multiple cells. Normally, you modify one cell at a time so Target would
return a one cell range in most of the cases, however it will return a
multi-cell range if you copy-paste multiple cells, etc.

Me is the short way of referring to the object in whose VBA module the macro
is. In this particular case Me refers to the worksheet which we are
monitoring for changes.

[A1] is the range that we actually monitor as we don't care about the rest
of the cells on this sheet.

So Intersect(Target, Me.[a1]) is trying to determine the range which is the
intersection of the range being changed and the range we are monitoring.
This will be the case if A1 is one of the cells changed. If A1 is not being
changed in this particular event, Intersect(Target, Me.[a1]) will return
Nothing, which is what we are trying to trap with the If...Then construct.

The Not operator changes boolean result (TRUE/FALSE) to its opposite, so the
statement "Not Intersect(Target, Me.[a1]) Is Nothing" actually means:

Intersect(Target, Me.[a1]) Is NOT Nothing

Therefore the statement "If Not Intersect(Target, Me.[a1]) Is Nothing Then
..." means: if the intersection between the 'range changed' and A1 is not
nothing (is a range), then proceed with the following action (otherwise do
nothing).

Hope this helps,

Regards,
KL


serdar said:
i am unfamiliar with vbasic syntax..so what is
Intersect( )
and
Is Nothing?


--If Not Intersect(Target, Me.[a1]) Is Nothing
 
Back
Top