Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I need some help with a code to undo an action. The code I have to do an action is below, this sorts cells into order from smallest to largest based on input of hours. Here is the code: Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim strPrompt As String Dim intbuttons As Integer Dim strTitle As String If Target.Address = Range("K2").Address Then strPrompt = "Do you want Put Staff into OT Order?" intbuttons = vbYesNo + vbInformation strTitle = "Galashiels Operational Resources © MN " If MsgBox(strPrompt, intbuttons, strTitle) = vbYes Then Range("A7:D16").Select ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Add Key:=Range("C7:C16" _ ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Staff OT").Sort .SetRange Range("A7:D16") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Range("F7:I16").Select ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Add Key:=Range("H7:H16" _ ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Staff OT").Sort .SetRange Range("F7:I16") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Range("A24:D33").Select ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Add Key:=Range( _ "C24:C33"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ xlSortNormal With ActiveWorkbook.Worksheets("Staff OT").Sort .SetRange Range("A24:D33") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Range("F24:I33").Select ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Add Key:=Range( _ "H24:H33"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ xlSortNormal With ActiveWorkbook.Worksheets("Staff OT").Sort .SetRange Range("F24:I33") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Range("A41:D50").Select ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Add Key:=Range( _ "C41:C50"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ xlSortNormal With ActiveWorkbook.Worksheets("Staff OT").Sort .SetRange Range("A41:D50") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Range("F41:I50").Select ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Staff OT").Sort.SortFields.Add Key:=Range( _ "H41:H50"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ xlSortNormal With ActiveWorkbook.Worksheets("Staff OT").Sort .SetRange Range("F41:I50") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Range("A1").Select End If End If End Sub What I am needing to do is have another code so that the user can select another cell K4 to undo the changes that have been made by the macro and to also clear contents of cells B3, B4, B5 and C5. Can anyone help me onthis code. Many thanks Mark |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to undo the delete action? | Excel Discussion (Misc queries) | |||
Undo a scroll action | Excel Programming | |||
Undo VB macro action | Excel Programming | |||
Undo a save action | Excel Discussion (Misc queries) | |||
undo/redo action | Excel Discussion (Misc queries) |