View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.misc
Jim May
 
Posts: n/a
Default Adding a Tab in a Macro

Dave:
Thanks for the clarification. I'm now better informed.
Jim

"Dave Peterson" wrote:

Pasting to a sheet is a change to that sheet--so the event fires.

If you want to stop the event from firing, you can turn off the event monitoring
and do the work.

application.enableevents = false
'do some stuff
application.enableevents = true

And cutting something from the sheet and pasting it elsewhere is seen as two
changes--one for the cut and one for the paste.

So I'm thinking that you're seeing the first pass (cutting A7:I7) drop to the
next line (B7 is part of that range)--so it doesn't exit the sub.

If you add a breakpoint on the Range("a7:i7").select line, then step through,
you'll see it go through the procedure twice.

Jim May wrote:

Dave: I was trying to help Michael out (privately) and had a few
questions. The Change event you are speaking to here is triggered as
follows (by first running AddNAME()

Sub ADDNAME() ' Macro (Only first 6 lines - like so):

Range("a7:I7").Select
Selection.Cut
ActiveWindow.ScrollRow = 561
ActiveWindow.SmallScroll Down:=398
Range("a990").Select
ActiveSheet.Paste

As a result of the 1st 6 lines of code (above) 2 or 3 things are happening,
which I do not understand..
1) Line 6 ActiveShet.Paste is triggering a Worksheet_Change Event. WHY????
2) The resulting WS-Change Event starts with statement:
If Intersect(Target, Range("b7")) Is Nothing Then Exit Sub
(At this point - In the immedaite window when I do ? Target.address ' I
get A7:I7 (??)
And after processing this line it (interpreting it as False) it proceeds to
the next line
where it Calls Look-Here1 (a standard module)..

Can you elaborate of a few of these points,
TIA,
Jim

"Dave Peterson" wrote in message
...
That's not checking to see if B7 is empty (or looks blank). It's just
checking
to see if the cell you changed was B7.

I like this style:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

if target.cells.count 1 then exit sub 'only one cell at a time

'exit unless it Is B7 that changed
If Intersect(Target, me.Range("$b$7")) Is Nothing Then Exit Sub

if isempty(target.value) then exit sub

Call Module22.Look_Here1
'the macro To Call when b7 changes

End Sub


michaelberrier wrote:

I've stepped through my code using F8 and have found an instance where
the code directs an Exit Sub if a certain cell is blank, but it is
continuing...here is the code.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Intersect(Target, Range("$b$7")) Is Nothing Then Exit Sub
'exit unless it Is c1 that changed

Call Module22.Look_Here1
'the macro To Call when c1 changes

End Sub

Cell B7 is empty, no values, no formulas, nothing, but the macro
proceeds to the next step and that's where it goes off kilter.

Any idea why it's doing that?

--

Dave Peterson


--

Dave Peterson