Undo Option Lost After Worksheet Event Macro

kwp004

Board Regular
Joined
Dec 27, 2016
Messages
93
Hi,

If the user makes a certain change, I have a worksheet level macro that makes some formatting changes. The macro works well. Unfortunately, whenever it runs, the user loses the ability to Undo.


Is there either:
i) a way to keep the macro, but preserve the ability to undo, or
ii) rewrite the macro, such that a more narrow scope of events triggers it? Currently, the macro runs anytime any changes are made to the worksheet, but I really only need it to run if changes are made in range I6 to I36.


Rich (BB code):
Dim irow As Long
    For irow = 6 To 35

If Range("AA" & irow) = "C" Then


    With Range("A" & irow).Resize(, 19)
        .Borders(xlEdgeTop).LineStyle = xlNone
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
    End With


Else
With Range("A" & irow).Resize(, 19)
        .Borders(xlEdgeTop).LineStyle = xlContinuous
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
    End With


End If
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Normally you should have the first structure if I understand you.

Code:
Sub Worksheet_change()
.....
End sub

For your point 2, you can change it to this

Code:
Sub Worksheet_change(ByVal Target As Range)
If not Intersect(Target,Range("I6:I36")) Is Nothing Then
....
End If
End sub

As for your point 1, the best will be to "preserve" the old data elsewhere and make another macro to "reput" the old data at the right place.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top