vba 根据行和列的特定条件选择表格中的单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5705353/
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-11 13:02:58  来源:igfitidea点击:

Selecting Cell in table based on specific criteria for both row and column

excelexcel-vbavba

提问by kathy

Hi I'm new to Excel and VBA, and I'm wondering if what I would like to do is possible, and how I can go about doing it.

嗨,我是 Excel 和 VBA 的新手,我想知道我想做的事情是否可行,以及如何去做。

I have a large table with two main criteria: Month and Name.

我有一个大表,有两个主要标准:月份和名称。

           January                     February

Name      Set A   Set B  Set C      Set A  Set B  Set C      

Frank       1       2      3          4      5      6

Harry       2       4      6          3      6      9

Sally       12      24     12         2      4       2

I need to be able to set the row (ex. Frank, Harry, or Sally), and the month that I'm working on (ex. February) and then paste values into Set A, Set B and Set C etc from another worksheet.

我需要能够设置行(例如 Frank、Harry 或 Sally)以及我正在处理的月份(例如二月),然后将值从另一个粘贴到 Set A、Set B 和 Set C 等中工作表。

How can I do this?

我怎样才能做到这一点?

回答by Roger

I think you may be looking for INDEX (Application.Index) and MATCH (Applicaiton.Match). They return row and column numbers that you can use to build cell locations.

我想你可能正在寻找 INDEX (Application.Index) 和 MATCH (Applicaiton.Match)。它们返回可用于构建单元格位置的行号和列号。

There's a pretty good example here http://www.mrexcel.com/forum/showthread.php?t=522804

这里有一个很好的例子http://www.mrexcel.com/forum/showthread.php?t=522804

If you are able to modify your month names to duplicate in each column, it will probably make your life easier.

如果您能够修改您的月份名称以在每一列中重复,它可能会让您的生活更轻松。

The trick is going to be matching the set and month to get the proper column. Here's an example of using an if statement around index/match to solve a problem like your month/set issue. http://www.mrexcel.com/forum/showthread.php?p=233645#239180'

诀窍是匹配集合和月份以获得正确的列。这是使用围绕索引/匹配的 if 语句来解决诸如月/集问题之类的问题的示例。http://www.mrexcel.com/forum/showthread.php?p=233645#239180'

Hope this helps!

希望这可以帮助!