我有这种非常格式不正确的数据,我必须每周工作。这里有一个例子:试图通过使用excel的relavence做一场比赛
Code: To: Total: Description: ------------------------------------------------------------- FD987 00001 5 Food/Snack/M&M
FD987 00001 5 Food/Snack/Pretzels
NA654 00001 5 Non-Alc/Soda/Sprite
NA654 00002 2 Non-Alc/Soda/Sprite
NA987 00002 2 Non-Alc/Soda/Lemonde
我要结束了该数据由“要”代码排序,各种数据总结了在每个类别分类汇总和分类汇总为整体“到”条目。像这样:
To: Total: Description: --------------------------------------------------- 00001 10 Food Subtotal
00001 5 Non-Alc Subtotal
00001 15 Grand total
00002 0 Food Subtotal
00002 4 Non-Alc Subtotal
00002 4 Grand total
我已经编写了获取“00001”和“00002”的代码。但我不知道该怎么做。我是否应该循环使用if和for的组合?
例如:
pseudo code:
for all i in UniqueToCodes
if (cell.value = i) then
Descriptions = {"Food", "Non-Alc"}
tempsum = 0
for all j in Descriptions
q = total for item j belonging to Descriptions belonging to UniqueToCodes
tempSum = tempSum + q
next j
end if
next i
或将向后循环更有效率?
例如,作为这样的:
pseudo-code:
for i = lastOccurenceOf(ToCode) to firstOccurenceOf(ToCode) -1
Descriptions = {"Food", "Non-Alc"}
for all j in Descriptions
q = total for item j belonging to Descriptions belonging to UniqueToCodes
tempSum = tempSum + q
next j
next i
(我知道“到”代码始终显示为块,且从未被其他代码感叹词即 总是像这样的:
00001 00001 00002
从未因为这个:
00001 00001 00003 00001)
也我如何存储所有这些临时款项?即“To”代码为“00001”的“Food”的tempSum和“Non-Alc”的tempSum?我知道字典对象只将一个属性映射到一个键。但是我需要将小计与Description和Grand Total合计到“To”代码中。你会说什么是解决这个问题的最好方法?任何帮助将不胜感激!谢谢!
你有没有考虑过使用数据透视表? – assylias 2012-03-09 18:24:16
同意,根据您的示例数据,关键点几乎肯定会更容易。 [良好的资源开始](http://www.ozgrid.com/Excel/excel-pivot-tables.htm) – Gaffi 2012-03-09 18:25:49
我第三个数据透视表的建议。你的数据非常完美。 – 2012-03-09 18:39:17