i have form for change case.. it contains RefEdit control , option button, command button....
1. by using RefEdit control I'm selecting Range..
2. Option button is for selecting Upper Case..
3. On click on command button the selected range value is change to Upper Case..
this is working fine...
but now i wanted to undo the action done by userform so i have used Application.Undo.. undo button is getting activated but it is not undoing the action plss help.. code I'm using is below...
Whenever i click Ctrl+Z it gives Msgbox("Can't undo") everytime... pls help
1. by using RefEdit control I'm selecting Range..
2. Option button is for selecting Upper Case..
3. On click on command button the selected range value is change to Upper Case..
this is working fine...
but now i wanted to undo the action done by userform so i have used Application.Undo.. undo button is getting activated but it is not undoing the action plss help.. code I'm using is below...
Code:
Private Type SaveRange
Val As Variant
Addr As String
End Type
Public OldWorkbook As Workbook
Public OldSheet As Worksheet
Private OldSelection() As SaveRange
Dim b, c
Dim i, j, k As Long
Private Sub btn_change_Click()
Set b = ActiveSheet.Range(ref_range.Text)
ReDim OldSelection(b.Cells.Count)
Set OldWorkbook = ActiveWorkbook
Set OldSheet = ActiveSheet
j = 1
If Application.CountBlank(b) = b.Cells.Count Then
MsgBox "Empty Range"
ref_range.SetFocus
Else
If opt_upper Then
For Each c In b
If c.Value <> "" Then
c.Value = UCase(c.Value)
OldSelection(j).Addr = c.Address
OldSelection(j).Val = c.Formula
j = j + 1
End If
Next
End If
ref_range.SetFocus
End If
Application.OnUndo "Undo the Change Case", "UndoCase"
End Sub
Sub UndoCase()
On Error GoTo Problem
Application.ScreenUpdating = False
OldWorkbook.Activate
OldSheet.Activate
For k = 1 To UBound(OldSelection)
Range(OldSelection(k).Addr).Formula = OldSelection(k).Val
Next k
Exit Sub
Problem:
MsgBox "Can't undo"
End Sub
Whenever i click Ctrl+Z it gives Msgbox("Can't undo") everytime... pls help