如何取消排序的数据(Excel VBA)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17689162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:10:56  来源:igfitidea点击:

How to Unsort the Sorted data ( Excel VBA)

excelvbaexcel-vbaexcel-2003

提问by user2589436

I'm now sorting some data using a VBA code. ( for some search feature)

我现在正在使用 VBA 代码对一些数据进行排序。(对于某些搜索功能)

After my search is complete I would like to unsort the data back into its original form. How do I do that?

搜索完成后,我想将数据重新排序为原始形式。我怎么做?

Thanks.

谢谢。

回答by user1759572

Just make a copy of the data before sort and set it back..
Other way: you need preserve keys before sort (with hash map) and resort array (after main sort) again by those keys.

只需在排序之前复制数据并将其设置回来..
其他方式:您需要在排序之前保留键(使用哈希映射)并通过这些键再次使用数组(在主排序之后)。

回答by Dr Nisha Arora

I am not sure how to do it using VBA coding. However, you've two options provided you haven't saved changes, if any:

我不确定如何使用 VBA 编码来做到这一点。但是,如果您没有保存更改(如果有),您有两个选项:

  1. Before sorting add a column with numbers running from 1. Then if you want to restore your sort, you can then sort on this column.
  2. In MS Excel 2010 version there is an option to unsort multiple/many columns in excel in one go:

    HOME->EDITING->SORT &FILTER drop down menu->CLEAR.

  1. 在排序之前添加一个数字从 1 开始的列。然后如果你想恢复你的排序,你可以在这个列上排序。
  2. 在 MS Excel 2010 版本中,有一个选项可以一次性取消对 Excel 中的多个/多列进行排序:

    首页->编辑->排序和过滤器下拉菜单->清除。

This will clear all the columns/rows in the that Worksheet.

这将清除该工作表中的所有列/行。

回答by user6213855

Ctrl+Z undoes the action if you have not saved it. Another option is to create another sheet and paste the data in there to use as a backup.

如果您尚未保存该操作,则 Ctrl+Z 会撤消该操作。另一种选择是创建另一个工作表并将数据粘贴在其中以用作备份。

回答by C. van Dorsten

This is something I had to resolve of late as well. This is how I did it.

这也是我最近必须解决的问题。我就是这样做的。

  1. Create a temporary index (just numbers 1..n) in the last sortcolumn + 1
  2. Include the temporary index column in the sort
  3. Do sorting and processing
  4. Sort using the temporary index
  5. Clear/delete the temporary index column
  1. 在最后一个 sortcolumn + 1 中创建一个临时索引(只是数字 1..n)
  2. 在排序中包含临时索引列
  3. 做排序和处理
  4. 使用临时索引排序
  5. 清除/删除临时索引列

Hope this helps someone.

希望这可以帮助某人。