Suggestion for macro undo

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
Evening,

I have a code which has a call to macro function at the end of it, the macro is shown below.
Basically the cells C2:D27 show an un-ordered placement but then the macro once runs places it from most popular to least popular sold items.

Now this works very good BUT i overlooked that the order MUST be put back to its un-ordered placement once ive viewed it,reason being when i select a part it then updates its stock sold quantity in the wrong place.
I thought some kind of reversal would be fine.

Now i am at a loss of how to do this.
I need to view the list but once finished then this reversal should happen,it can be time related so can you suggest something please.
Best if im in control of how it works,button etc but needs to be done before i select another part or its saved or sheet closed etc.



Code:
Sub SORTSOLDITEMS()'
' SORTSOLDITEMS Macro
'


'
    Sheets("SOLD ITEMS").Range("C2:D14").Copy Sheets("HONDA SHEET").Range("C1")
    Sheets("SOLD ITEMS").Range("C15:D27").Copy Sheets("HONDA SHEET").Range("E1")
    With Sheets("HONDA SHEET").Range("C1:F13").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With
         Sheets("HONDA SHEET").Select
         Range("A13").Select
         ActiveWorkbook.Save
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,
just an update.

I have placed the following code at the begining of the macro.
I will take a copy of the range of cells before the sort takes place.


I will now await a suggestion for how i will copy / paste it back once finished viewing.


Code:
Range("C1:F17").Copy Range("I1")
 
Upvote 0
Can you post the code that does the sorting and point out exactly what sheet and range you want to return to its original presorted arrangement and when you want that to happen?
 
Upvote 0
Hi,

The sort code is shown below.

I was thinking that after this part Range("A13").Select happens then a Msgbox pops up advising me to click OK after ive finished viewing to then copy the cell values ("I1:L17") back to C1 then save Activeworkbook ?
What do you think ??



Code:
Sub SORTSOLDITEMS()'
' SORTSOLDITEMS Macro
'


'
    Sheets("SOLD ITEMS").Range("C2:D14").Copy Sheets("HONDA SHEET").Range("C1")
    Sheets("SOLD ITEMS").Range("C15:D27").Copy Sheets("HONDA SHEET").Range("E1")
    With Sheets("HONDA SHEET").Range("C1:F17").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With
         Sheets("HONDA SHEET").Select
         Range("A13").Select
         ActiveWorkbook.Save
End Sub
 
Upvote 0
this code does no sorting, its simply copying 2 ranges and coloring 1
 
Upvote 0
Guess I'm missing something. Can you tell me where in the code the sort takes place?
 
Upvote 0
Sorry my mistake.

See below

Code:
Sub LEADERBOARD()    '' leaderboard Macro'
    Range("C1:F17").Copy Range("I1")
    Worksheets("HONDA SHEET").Range("C1:D17").Copy Worksheets("SOLD ITEMS").Range("C2:D19")
    Worksheets("HONDA SHEET").Range("E1:F17").Copy Worksheets("SOLD ITEMS").Range("C19:D35")


    ActiveWorkbook.Worksheets("SOLD ITEMS").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("SOLD ITEMS").Sort.SortFields.Add Key:=Range("D2"), _
    SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortTextAsNumbers
    With Worksheets("SOLD ITEMS").Sort
        .SetRange Range("C2:D35")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With


    With Worksheets("SOLD ITEMS").Range("C2:D35").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        End With
    Application.Goto Sheets("SOLD ITEMS").Range("A5")
    Call SORTSOLDITEMS
    End Sub
 
Upvote 0
That's better. So is it Sheets("SOLD ITEMS").Range("C2:D35") you want to restore after the SORTSOLDITEMS macro runs? If yes, are there any formulas in that range? And what sheet do you want to look at before the restoration?
 
Last edited:
Upvote 0
No
It gets hard to explain now.

Let me put a link here for you to see in 2 minutes
 
Upvote 0
Hi,
Take a look at this https://drive.google.com/open?id=1-X1ycVwh-raANC8tAf9Uck2od7AlLBrM

The list shown on HONDA SHEET is in the order of how the code add the stock sold quantity.
If you click on the blue leader board photo it then copies from Honda Sheet & sorts / pastes to SOLD ITEMS then comes back to HONDA SHEET but now is the most popular to least popular item.

Thing to remember is the cell layout on Honda Sheets & then the vertical list on the other as there wasnt space to do it the same for both.
I also didnt know how to do it but got by doing it this way.

Yes its long winded but it was working for me & spent too long scratching my head for the correct way.

Have a play like this,
Copy cell A23 and paste it into cell A13

Then just go to cell F21 and make a selection.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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