GTretick
Member
I've created a routine that copies a range of cells in a worksheet (U3 to AK3) and copies it to another worksheet summary page where it selects the appropriate row (information is contained in cell T3) and pastes the information there.
The routine works well when I run the macro manually but when I try to run the macro on worksheet deactivation, it runs into problems.
using F8 I've traced it to the fact that when I get to the Sheets("Cost Control").Select line, it reactives the Worksheet_Deactivate routine again midstream which fouls things up.
Can I get it to ignore the "loop" that is being caused by this within the Worksheet_Deactivate routine?
Maybe the code needs amending to tackle the problem differently?
Thanks.
The routine works well when I run the macro manually but when I try to run the macro on worksheet deactivation, it runs into problems.
using F8 I've traced it to the fact that when I get to the Sheets("Cost Control").Select line, it reactives the Worksheet_Deactivate routine again midstream which fouls things up.
Can I get it to ignore the "loop" that is being caused by this within the Worksheet_Deactivate routine?
Maybe the code needs amending to tackle the problem differently?
Thanks.
Code:
Private Sub Worksheet_Deactivate()
'Moves data from detail sheet to Summary
Dim x As Integer: x = Range("T3").Value
Range("U3:AK3").Select
Selection.Copy
Sheets("Cost Control").Select
Cells(x, 2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
Last edited by a moderator: