简体   繁体   English

VBA函数查找范围内的单元格值

[英]VBA function to find cell value within range

Beginner vba user. 初学者vba用户。

I'm trying to create a function that will allocate the correct client_id in cell C2:C6 , using the House and the Date values. 我正在尝试创建一个函数,该函数使用HouseDate值在单元格C2:C6分配正确的client_id

在此处输入图片说明

One House could have had multiple client_ids over time, so I need to allocate the correct client_id based on the Joining Date . 一所House随着时间的流逝可能会有多个client_ids ,因此我需要根据Joining Date分配正确的client_id

The function needs to find all instances where the House value is the same in the range A9:C13 . 函数需要查找House值在A9:C13范围内相同的所有实例。

Below is the desired outcome: 以下是理想的结果:

在此处输入图片说明

The first step is setting the range, and then looping through this range for column B to find all instances where the house number matched the value in this column. 第一步是设置范围,然后在B列中遍历该范围,以查找门牌号与该列中的值匹配的所有实例。

If I set the known range: 如果我设定已知范围:

Dim rng As Range: Set rng = Application.Range("Data!A10:C13")

How do I loop over this range for column B ? 如何在B列的此范围内循环?

After editing to properly reference a parent worksheet, run: 编辑以正确引用父级工作表后,运行:

range("c2:c6").formula = "=INDEX(A$10:A$13, AGGREGATE(14, 6, ROW($1:$4)/((C$10:C$13<A2)*(B$10:B$13=B2)), 1))"

This formula does depend on ascending join dates (per each house) in C10:C13. 此公式的确取决于C10:C13中的加入日期(每个房屋)。

在此处输入图片说明

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

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