Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Why does a loop start ?

Please explain the reson why "Act" become = 0 after the pastespecial
operation and ws_change starts? The whole reason with the Act thing is that
it _should_prevent_a_loop_ when event ws_change happens. Look at the mark at
FormatTemp sub where it all go wrong....

I can't use "Application.eventenable = false" approach because it seem to
wipe out the clipboard... . I have no other worksheet_event etc in the
workbook.

/Thanks

Private Sub Worksheet_Change(ByVal Target As Range)
' *********
' Start a format restore operation when any change take place
' Act is used as a variable to prevent a loop when ForamtTemp causes any
changes
' *********
Dim Act As Integer
' "After the pastespecial in FormatTemp causes a change, a
' msgbox show Act = 0 here - why ?????"
If Not Act = 1 Then
Call FormatTemp
Else:
Exit Sub
End If
Act = 0
End Sub


Sub FormatTemp()
'**********
'SetSaveLoc and GetSaveLoc log and activate the current worksheet, workbook
and range
'**********
Dim Act As Integer
Act = 1
ActiveSheet.Unprotect
Call SetSaveLoc
Blad200.Unprotect
Blad200.Cells.Copy
ActiveSheet.Cells.Select ' Act = 1
Selection.PasteSpecial Paste:=xlPasteFormats,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

' HERE does the above action trigg worksheet_activate
' and make Act = 0 causing a loop of some reson - why? ????

ActiveSheet.Protect AllowFormattingCells:=False
ActiveSheet.EnableSelection = xlUnlockedCells
Call GetSaveLoc
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Why does a loop start ?

Because you define Act in each of the modules a) it is effectively a
different variable in each module and b) its life ends when the module
exits. You need to define Act once only before all of the modules so that
the value can be passed from one to the next.

Regards

Trevor


wrote in message
...
Please explain the reson why "Act" become = 0 after the pastespecial
operation and ws_change starts? The whole reason with the Act thing is

that
it _should_prevent_a_loop_ when event ws_change happens. Look at the mark

at
FormatTemp sub where it all go wrong....

I can't use "Application.eventenable = false" approach because it seem to
wipe out the clipboard... . I have no other worksheet_event etc in the
workbook.

/Thanks

Private Sub Worksheet_Change(ByVal Target As Range)
' *********
' Start a format restore operation when any change take place
' Act is used as a variable to prevent a loop when ForamtTemp causes any
changes
' *********
Dim Act As Integer
' "After the pastespecial in FormatTemp causes a change, a
' msgbox show Act = 0 here - why ?????"
If Not Act = 1 Then
Call FormatTemp
Else:
Exit Sub
End If
Act = 0
End Sub


Sub FormatTemp()
'**********
'SetSaveLoc and GetSaveLoc log and activate the current worksheet,

workbook
and range
'**********
Dim Act As Integer
Act = 1
ActiveSheet.Unprotect
Call SetSaveLoc
Blad200.Unprotect
Blad200.Cells.Copy
ActiveSheet.Cells.Select ' Act = 1
Selection.PasteSpecial Paste:=xlPasteFormats,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

' HERE does the above action trigg worksheet_activate
' and make Act = 0 causing a loop of some reson - why? ????

ActiveSheet.Protect AllowFormattingCells:=False
ActiveSheet.EnableSelection = xlUnlockedCells
Call GetSaveLoc
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Why does a loop start ?

Thank you, I learned something there. I'm new with using ws_Change and find
now that where ever I place the "dim act", I get the loop. I tried to create
a new sub for evaluation etc with no luck etc. Can you just give me a more
precise hint of where/how to place the dim Act?

/Thanks again


"Trevor Shuttleworth" skrev i meddelandet
...
Because you define Act in each of the modules a) it is effectively a
different variable in each module and b) its life ends when the module
exits. You need to define Act once only before all of the modules so that
the value can be passed from one to the next.

Regards

Trevor


wrote in message
...
Please explain the reson why "Act" become = 0 after the pastespecial
operation and ws_change starts? The whole reason with the Act thing is

that
it _should_prevent_a_loop_ when event ws_change happens. Look at the

mark
at
FormatTemp sub where it all go wrong....

I can't use "Application.eventenable = false" approach because it seem

to
wipe out the clipboard... . I have no other worksheet_event etc in the
workbook.

/Thanks

Private Sub Worksheet_Change(ByVal Target As Range)
' *********
' Start a format restore operation when any change take place
' Act is used as a variable to prevent a loop when ForamtTemp causes any
changes
' *********
Dim Act As Integer
' "After the pastespecial in FormatTemp causes a change, a
' msgbox show Act = 0 here - why ?????"
If Not Act = 1 Then
Call FormatTemp
Else:
Exit Sub
End If
Act = 0
End Sub


Sub FormatTemp()
'**********
'SetSaveLoc and GetSaveLoc log and activate the current worksheet,

workbook
and range
'**********
Dim Act As Integer
Act = 1
ActiveSheet.Unprotect
Call SetSaveLoc
Blad200.Unprotect
Blad200.Cells.Copy
ActiveSheet.Cells.Select ' Act = 1
Selection.PasteSpecial Paste:=xlPasteFormats,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

' HERE does the above action trigg worksheet_activate
' and make Act = 0 causing a loop of some reson - why? ????

ActiveSheet.Protect AllowFormattingCells:=False
ActiveSheet.EnableSelection = xlUnlockedCells
Call GetSaveLoc
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Why does a loop start ?

Trevor,

If I leave out the "Dim Act " moment compleatly, the Act value still resets
to "empty" when the pastespecial command trigger the ws_Change sub.
A msgbox before pastespecial show act = 1, but a msgbox in the beginning of
ws_change show act= empty.

I there a logic into this?

/Nob.



"Trevor Shuttleworth" skrev i meddelandet
...
Because you define Act in each of the modules a) it is effectively a
different variable in each module and b) its life ends when the module
exits. You need to define Act once only before all of the modules so that
the value can be passed from one to the next.

Regards

Trevor


wrote in message
...
Please explain the reson why "Act" become = 0 after the pastespecial
operation and ws_change starts? The whole reason with the Act thing is

that
it _should_prevent_a_loop_ when event ws_change happens. Look at the

mark
at
FormatTemp sub where it all go wrong....

I can't use "Application.eventenable = false" approach because it seem

to
wipe out the clipboard... . I have no other worksheet_event etc in the
workbook.

/Thanks

Private Sub Worksheet_Change(ByVal Target As Range)
' *********
' Start a format restore operation when any change take place
' Act is used as a variable to prevent a loop when ForamtTemp causes any
changes
' *********
Dim Act As Integer
' "After the pastespecial in FormatTemp causes a change, a
' msgbox show Act = 0 here - why ?????"
If Not Act = 1 Then
Call FormatTemp
Else:
Exit Sub
End If
Act = 0
End Sub


Sub FormatTemp()
'**********
'SetSaveLoc and GetSaveLoc log and activate the current worksheet,

workbook
and range
'**********
Dim Act As Integer
Act = 1
ActiveSheet.Unprotect
Call SetSaveLoc
Blad200.Unprotect
Blad200.Cells.Copy
ActiveSheet.Cells.Select ' Act = 1
Selection.PasteSpecial Paste:=xlPasteFormats,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

' HERE does the above action trigg worksheet_activate
' and make Act = 0 causing a loop of some reson - why? ????

ActiveSheet.Protect AllowFormattingCells:=False
ActiveSheet.EnableSelection = xlUnlockedCells
Call GetSaveLoc
End Sub



"



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Why does a loop start ?

Yes, there is a logic to it. Leaving out the definition altogether has a
similar effect to defining the variable in each module. It will, however
default to a variant and if you haven't set the variable in the code it will
be empty.

This should work:

Dim Act As Integer

Private Sub Worksheet_Change(ByVal Target As Range)
' *********
' Start a format restore operation when any change take place
' Act is used as a variable to prevent a loop when ForamtTemp causes any
changes
' *********
:
If Not Act = 1 Then
Call FormatTemp
Else:
Exit Sub
End If
Act = 0
End Sub

Sub FormatTemp()
'**********
'SetSaveLoc and GetSaveLoc log and activate the current worksheet, workbook
and range
'**********
Act = 1
:
:
End Sub

Alternatively, or if it doesn't work, try defining Act as a Public variable
in a General module

I'm not keen on using negative conditions where there are only two options.
It is better, in my opinion, to use the positive condition ... it makes the
logic easier to follow and should identify any design errors:

If Act = 0 Then
Call FormatTemp ' This routine sets Act = 1
Else:
Exit Sub
End If
Act = 0 ' Here we set Act = 0 again

I'm afraid I'm not sure what you want to achieve given that every time there
is a Worksheet change exits you'll have reset Act to 0. So, I'm a bit
confused !

Regards

Trevor


wrote in message
...
Trevor,

If I leave out the "Dim Act " moment compleatly, the Act value still

resets
to "empty" when the pastespecial command trigger the ws_Change sub.
A msgbox before pastespecial show act = 1, but a msgbox in the beginning

of
ws_change show act= empty.

I there a logic into this?

/Nob.



"Trevor Shuttleworth" skrev i meddelandet
...
Because you define Act in each of the modules a) it is effectively a
different variable in each module and b) its life ends when the module
exits. You need to define Act once only before all of the modules so

that
the value can be passed from one to the next.

Regards

Trevor


wrote in message
...
Please explain the reson why "Act" become = 0 after the pastespecial
operation and ws_change starts? The whole reason with the Act thing is

that
it _should_prevent_a_loop_ when event ws_change happens. Look at the

mark
at
FormatTemp sub where it all go wrong....

I can't use "Application.eventenable = false" approach because it seem

to
wipe out the clipboard... . I have no other worksheet_event etc in the
workbook.

/Thanks

Private Sub Worksheet_Change(ByVal Target As Range)
' *********
' Start a format restore operation when any change take place
' Act is used as a variable to prevent a loop when ForamtTemp causes

any
changes
' *********
Dim Act As Integer
' "After the pastespecial in FormatTemp causes a change, a
' msgbox show Act = 0 here - why ?????"
If Not Act = 1 Then
Call FormatTemp
Else:
Exit Sub
End If
Act = 0
End Sub


Sub FormatTemp()
'**********
'SetSaveLoc and GetSaveLoc log and activate the current worksheet,

workbook
and range
'**********
Dim Act As Integer
Act = 1
ActiveSheet.Unprotect
Call SetSaveLoc
Blad200.Unprotect
Blad200.Cells.Copy
ActiveSheet.Cells.Select ' Act = 1
Selection.PasteSpecial Paste:=xlPasteFormats,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

' HERE does the above action trigg worksheet_activate
' and make Act = 0 causing a loop of some reson - why? ????

ActiveSheet.Protect AllowFormattingCells:=False
ActiveSheet.EnableSelection = xlUnlockedCells
Call GetSaveLoc
End Sub



"





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
OT :Start your own online business today !start making dollars [email protected] Excel Discussion (Misc queries) 0 May 6th 06 09:29 PM
Start spreadsheet with WinXP start Gordon Gradwell Excel Worksheet Functions 1 July 13th 05 11:35 AM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM
From worksheet enter DO-Loop start & end code Bob Leonard[_2_] Excel Programming 1 December 1st 03 09:42 PM


All times are GMT +1. The time now is 09:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"