excel vba:如何根据列值对行进行排序 [英] excel vba: How to Sort Group of Row based on column value

查看:1289
本文介绍了excel vba:如何根据列值对行进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的excel中有以下数据。而我的要求就是根据Forecast Age按降序排列一组行。我已经在excel中尝试了内置的排序函数,但不符合我的要求。例如,我的预测年龄在 Range(BO54) = 17和 Range(BO88) = 19,  范围(BO88)值大于其他值,因此应该是的组是范围(A78:CA91)



简而言之,我想要第88行,它是 Range(A78:CA91)在顶部。有没有办法这样做,不排序范围内的数据(A78:CA91)



< br>

解决方案

我可以建议你的方式可能是冗长的代码。



首先,您可以在所有行上运行循环,条件是如果描述=预测年龄然后将其粘贴到新的工作表中。这将给您列出每个house age 的行列表。 根据年龄排序,并添加一个将根据年龄分配 rank()的列。



此后,您在主数据中添加了一个排列,并将 vlookup 以上获得的排列到每个房子,然后最终排序整个表基于这些排名。
您应该获得期望的结果。



这只是一个头脑。您可以优化流程并即时完成。


I have the following data in my excel. and my requirements is to sort a group of rows based on Forecast Age in Descending order. I have already tried the built in sort function in excel but it doesn't meet my requirements.

Let's say for example my forecast age is in Range("BO54")=17 and Range("BO88")=19,  Range("BO88") value is bigger than the other so it should to be on the top.  Range("BO88")'s group is Range("A78:CA91") .

In short I want 88th row and it's group of row which is Range("A78:CA91") to be at the top. Is there a way to do this without sorting the data within Range("A78:CA91")?



解决方案

Well I can suggest you one way which might be lengthy to code.

First you can run a loop on all rows with a condition that if "Description" = "Forecast Age" then paste it in a new sheets. This will give you list of rows with every "house" and age. Sort it based on age and add a column which will assign rank() it based on age.

After this add a rank column in your main data and vlookup the above obtained ranks to each house and then finally, sort the entire table based on these ranks. You should obtain the result you expect.

This is just a heads up. You can optimize the process and improvise it.

这篇关于excel vba:如何根据列值对行进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆