简体   繁体   中英

VBA function to find cell value within range

Beginner vba user.

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.

在此处输入图片说明

One House could have had multiple client_ids over time, so I need to allocate the correct client_id based on the Joining Date .

The function needs to find all instances where the House value is the same in the range 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.

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 ?

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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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