LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
AC AC is offline
external usenet poster
 
Posts: 5
Default Undo a Worksheet_Change Event Causes run-time error '10'

Hello,
I have a spreadsheet that tracks scheduled and completed dates for
some tasks. These tasks are color formatted based on how the scheduled
dates relate to Today() or if the task has been completed. Since I
have more than three conditions (Excel 2003) I am applying the
conditional formatting with a Worksheet_Change Event. This wipes out
the Undo function.
Using John Walkenbach's code to 'Undo a VBA subroutine', I get a run-
time error '10' when I select Edit--Undo. Below are my code pieces.
Can anybody help, please? Any suggestions/solutions are greatly
appreciated.

Thanks so much.
Regards,
A. Crawford

=============================
Conditional Formatting
=============================

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("C3:I50")) Is Nothing Then
Select Case Target.Column
Case 3
If Target.Offset(0, 5).Value < Empty Then
icolor = 34
ElseIf Target.Offset(0, 5).Value = Empty Then
If Target < Date Then
icolor = 3
ElseIf Target = Date And Target <= Date + 7 Then
icolor = 4
ElseIf Target = Date And Target = Date + 7 And
Target <= Date + 14 Then
icolor = 27
Else
icolor = xlcolornone
End If
End If
Range(Target.Address, Target.Offset(0,
6).Address).Interior.ColorIndex = icolor
Case 8
If Target < Empty Then
icolor = 34
ElseIf Target = Empty Then
If Target < Date Then
icolor = 3
ElseIf Target = Date And Target <= Date + 7 Then
icolor = 4
ElseIf Target = Date And Target = Date + 7 And
Target <= Date + 14 Then
icolor = 27
Else
icolor = xlcolornone
End If
End If
Range(Target.Offset(0, 1).Address, Target.Offset(0,
-5).Address).Interior.ColorIndex = icolor
End Select
End If

Call Module1.Memo

End Sub

===========================
Undo modules
===========================

Type SaveRange
Val As Variant
Addr As String
End Type

Public OldWorkbook As Workbook
Public OldSheet As Worksheet
Public OldSelection() As SaveRange

Sub Memo()
If TypeName(Selection) < "Range" Then Exit Sub
ReDim OldSelection(Selection.Count)
Set OldWorkbook = ActiveWorkbook
Set OldSheet = ActiveSheet
i = 0
For Each cell In Selection
i = i + 1
OldSelection(i).Addr = cell.Address
OldSelection(i).Val = cell.Formula
Next cell

Application.ScreenUpdating = False
Application.OnUndo "undo", "UndoZero"

End Sub

Sub UndoZero()
On Error GoTo Problem

Application.ScreenUpdating = False
OldWorkbook.Activate
OldSheet.Activate

For i = 1 To UBound(OldSelection)
Range(OldSelection(i).Addr).Formula = OldSelection(i).Val
Next i
Exit Sub

Problem:
MsgBox "Can't undo."
End Sub
 
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
Error handler question in Worksheet_Change event Sam Kuo[_3_] Excel Programming 3 March 12th 08 08:47 PM
Worksheet_change event handler error gen Excel Discussion (Misc queries) 0 January 18th 08 04:55 AM
Help with Worksheet_Change event time stamp Little Penny Excel Programming 3 December 1st 06 11:21 AM
Error with Target.Name.Name in Worksheet_Change event SuperJas Excel Programming 2 January 8th 04 03:26 AM
Worksheet_Change & Undo Mike Excel Programming 4 December 14th 03 03:48 AM


All times are GMT +1. The time now is 06:58 AM.

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

About Us

"It's about Microsoft Excel"