基于 Excel 中的第二列创建子列表
我有两列,第一列有对象的名称,第二列是它所属的人。 我想要每个人都有一张新表来列出他们分配给他们的内容。 这是一个例子:
dog F
cat F
bell S
whistle
bird F
弗雷德有一只狗、一只猫和一只鸟; 斯科特有一个铃铛; 而且没有人在他们的页面上有口哨。 现在做一个简单的 IF() 我可以让它看起来像这样 Fred 的页面
TOP OF ROW
dog
cat
bird
和 Scott 的页面看起来像
TOP OF ROW
bell
但是我希望 Fred 的页面看起来像
TOP OF ROW
dog
cat
bird
而 Scott 的页面是一样的。
我目前的思路是在 D 中的隐藏列中使用 =VLOOKUP($C$1,Items!A2:C1000,3)
来告诉我我的数据位于哪一行,(其中 C 列on Items 是一个隐藏列,其中包含行的行号,C1 是搜索参数(S 或 F)),然后 =IFERROR(CELL("contents",INDIRECT(ADDRESS($D2,2,1, TRUE,"Items"))),"")
,但是我除了将搜索数组的行索引更改为 1+ 最后找到的项目(我还没弄清楚该怎么做)之外,我不能弄清楚如何继续搜索下一个项目。 我了解 C++ 和 C#,但以前从未使用过 VBA 编码,而且我严重依赖 MSDN,据我所知,MSDN 没有专门介绍 Excel API 的部分。
I have two columns, the first column will have the name of a object, the second is who it belongs to. I want a new sheet for each person to list what they had assigned to them. here is a example:
dog F
cat F
bell S
whistle
bird F
So Fred has a dog, cat, and a bird; Scott has a bell; and no one has a whistle on their page. Now doing a simple IF() i can get it to look like this for Fred's page
TOP OF ROW
dog
cat
bird
And Scott's page will look like
TOP OF ROW
bell
however I want Fred's to look like
TOP OF ROW
dog
cat
bird
and Scott to be the same.
My current train of thought is to use =VLOOKUP($C$1,Items!A2:C1000,3)
in a hidden column in D to tell me which row my data is in, (where Column C on Items is a hidden column with the row number of the row and C1 is the search parameter (S or F)), then =IFERROR(CELL("contents",INDIRECT(ADDRESS($D2,2,1,TRUE,"Items"))),"")
, however I other than changing my row index of my search array to 1+ the last found item (which i have not figured out how to do) I can not figure out how to continue searching for the next item.
I know C++ and C# but never have coded in VBA before and I rely heavily on the MSDN and to my knowelge there is no MSDN section dedicated to the Excel API.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需任何 VBA 代码即可获得所需列表的一种方法是使用高级过滤器。
在工作表 1 上,输入列表输入如下
在sheet2上输入过滤条件(此条件意味着在Owned by列中包含F)
最后在sheet3上,调用高级过滤函数,如下所示
确保选择复制到另一个位置
选择sheet1输入列表作为列表范围
选择sheet2过滤条件作为条件范围
并选择sheet3中的某个位置作为输出范围(复制到条目)
如果您更喜欢沿着以下路线走下去excel VBA编程良好的第一步是尝试excel中的宏记录器(工具-宏-记录宏)
祝你好运!
One way of achieving the list that you are looking for without any VBA code is to make use of the advanced filter.
On sheet 1 the input list is entered as follows
on sheet2 enter the filter criteria (this criteria means contains F in Owned by column)
and finally on sheet3, call the advanced filter function like this
make sure to select copy to another location
select the sheet1 input list as the list range
select the sheet2 filter criteria as the criteria range
and select somewhere in sheet3 as the output range (the copy to entry)
If you prefer to go down the route of excel VBA programming a good first step is to try out the macro recorder in excel (tools - macros - record macro)
good luck!
有一个很好的方法可以使用 Excel 中的函数来完成此操作。
本质上,您需要创建一个正在运行的 countif
因此,在 C2 中,您将拥有
=COUNTIF($B$2:$B2,"F")
显然,“F”也可以是对另一个单元格的引用。 如果您将此公式填入范围内,它将扩大范围。 例如。 在 C3 中,它会显示=COUNTIF($B$2:$B3,"F")
这将为您提供示例中 C 列中的运行总计,这意味着:
事实上,你有 3 个 2 并不重要,因为 vlookup 总是会匹配到它找到的第一个匹配项。
这项技术有很多不同的应用。 根据数据的不同,您可能会发现将其放在数据的左侧更容易,因此 VLOOKUP 会更容易。
There is a good way of doing this with functions in excel.
Essentially you need to create a running countif
So in C2 you would have
=COUNTIF($B$2:$B2,"F")
Obviously the "F" could also be a reference to another cell. If you fill this formula down the range it will expand the range. Eg. in C3 it will say=COUNTIF($B$2:$B3,"F")
This will give you a running total in column C in your example this would mean:
The fact that you have 3 2s doesn't matter because a vlookup will always match to the first match it finds.
This technique has a lot of different applications. And depending on the data you may find it easier to put this on the left of the data so the VLOOKUP will be easier.