简体   繁体   English

Excel:从“最小到最大”到“AZ”的排序标准不一致

[英]Excel: Inconsistent sorting criteria from 'Smallest to Largest' to 'A-Z'

Situation: I am pulling information from a database and exporting it into an Excel 2010 template.情况:我从数据库中提取信息并将其导出到 Excel 2010 模板中。 The data consists of unique IDs (numeric), dates, and text in their respective columns.数据由各自列中的唯一 ID(数字)、日期和文本组成。 When going to sort, Excel usually recognizes the unique IDs as text and gives me the option of 'AZ' which yields the correct result.在进行排序时,Excel 通常会将唯一 ID 识别为文本,并为我提供“AZ”选项,从而产生正确的结果。

Problem: Occasionally when sorting the unique IDs, Excel will give me the option to sort from 'Smallest to Largest' and when this happens the report yields a wildly incorrect result.问题:有时在对唯一 ID 进行排序时,Excel 会给我从“最小到最大”排序的选项,当发生这种情况时,报告会产生非常不正确的结果。

Pattern: The sorting criteria is the only common denominator when a report fails, which makes little sense as they are both ascending orders.模式:排序标准是报告失败时的唯一公分母,这没什么意义,因为它们都是升序。 This issue only occurs ~20% of the time.此问题仅发生约 20% 的时间。 The other times it sorts correctly from 'AZ' as it does in the other worksheets within the same template.其他时候,它从“AZ”正确排序,就像在同一模板中的其他工作表中一样。

-I've tried changing Number Format within the drop down to 'Text' 'General' and 'Numbers' -I've tried manually sorting the data through filters as opposed to sort hierarchies -I've tried clearing the table, and re-copying/pasting the data into the template's worksheet. - 我尝试将下拉菜单中的数字格式更改为“文本”、“常规”和“数字”-我尝试通过过滤器手动对数据进行排序而不是排序层次结构-我尝试清除表格,然后重新- 将数据复制/粘贴到模板的工作表中。 This seems to work, but as the end goal is automation, I'd like to find out what the root cause is.这似乎有效,但由于最终目标是自动化,我想找出根本原因是什么。

Expected result: Numeric data copied and pasted into the field to be sorted from 'A-Z', resulting in a successful report.预期结果:将数字数据复制并粘贴到要从“A-Z”排序的字段中,从而生成成功的报告。

Actual result: Numeric data copied and pasted into the field typically results in the sort option of "A-Z', but occasionally sorts from 'Smallest to Largest' resulting in a failed report.实际结果:复制并粘贴到字段中的数字数据通常会导致排序选项为“A-Z”,但有时会从“最小到最大”排序,从而导致报告失败。

Excel is designed for numbers - and is generally very helpful in coercing text to numbers where appropriate. Excel 专为数字而设计 - 通常在适当的情况下将文本强制转换为数字非常有帮助。 However, once in Number format the reverse is not easy.但是,一旦采用数字格式,则相反并不容易。 As you have discovered, merely choosing Text as format is not enough.正如您所发现的,仅选择Text作为格式是不够的。

A clue is whether or not (assuming activated) the cells show green triangles.一个线索是(假设已激活)单元格是否显示绿色三角形。

Other than starting afresh with data entry into a cell already formatted as Text, the conventional solution for conversion with code is to prepend a quote, though appending a space would also serve.除了重新开始将数据输入到已格式化为文本的单元格中之外,使用代码进行转换的传统解决方案是在前面加上一个引号,尽管附加一个空格也可以。

Other than that, the easiest mass conversion approach may be to copy into Word (Keep text only) and copy back to Excel with pasting as Text.除此之外,最简单的批量转换方法可能是复制到 Word(仅保留文本)并粘贴为文本复制回 Excel。

The better solution may be to store IDs as text and prepend 0 s to a standard length.更好的解决方案可能是将 ID 存储为文本并在标准长度前添加0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM