View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default help with an event driven sub argument please

Hello Mark,

"Mark Dvorkin" wrote 1. Do I need to set the Target range within the sub
body
or XL does it for me with the declaration
Target As Excel.Range
setting it to A1:maxColmaxRow? My actual range is B2:X37


1. Target is declared as an argument, so don't need to declare it again
2. Target is the range on which the current event has been triggered (the
range affected by change, selection change, etc.), so you shouldn't be
changing it, but using as is.
3. By setting Target to A1:maxColmaxRow, it is no longer Target, but another
range so what is the point of changing it.
4. Usually, if you want to check wheather the Target range falls in or
intersects with a specific range you would use either:

If Not Intersect(Target, Range("A1:A" & maxColmaxRow)) Is Nothing Then
'your code here
End If

or the one that you actually use

2. Why the sub must be in worksheet code module (right-click
the worksheet tab and choose View Code) and my prevDay(Ref) function
and other VBA code must be in the Module1 (insert module)?


1. The event procedure must be in the module whose event is being captured,
I guess, for obvious reasons.
2. Your functions don't have to be in a standard module if you want to use
them from a specific class module (e.g. Worksheet) - you can put them into
the same module as the event procedure.
3. If you want the functions to be directly available for other modules or
as a spreadsheet function then you are better off putting them into standard
modules e.g. Module1.

When I make a copy of the sheet within the workbook (Jul05, Aug05)
each of which has one sheet per day, will the code be repeated that
many times?


Yes,the code will be multiplied if you copy a sheet which contains code.
I guess you should consider the ThisWorkbook event SheetChange if you want
to capture the event on multiple sheets

Privet,
KL