简体   繁体   中英

How to create dynamic ranges with dynamic start and end using a formula in Excel

I have a large data.table (more than 34k rows), and I have several rows grouped according to the sample name. Each data point represents a measurement acquired in a specific coordinate. In order to link and evaluate data from two tables, I need to match coordinates from these tables.

This is the formula I began with:

=INDEX(Particle!$D$4:$D$25,MATCH(SMALL((ABS(C5-Particle!$A$4:$A$25)^2+ABS(D5-Particle!$B$4:$B$25)^2)^(0.5),1),(ABS(C5-Particle!$A$4:$A$25)^2+ABS(D5-Particle!$B$4:$B$25)^2)^(0.5),0))

I would like to find a way to substitute the "Particle: X$XX$X" ranges to automatically get a cell range based on the text content in a column sorted in ascending order.

So this is what I want the function to do to define my cell range: "Find the first cell in this column where the text "A -20 Midds*" appears, and return the cell address, then find the last cell where the same text appears, and return the cell address." I want to have this function nested in this other one shown before that evaluates the distance in 2D between several points, but the database is so large that I don't want to manually define each of the ranges.

Is there a way of doing this? I already tried the combination of INDEX(CELL("address",... ) but it gives an error.

You can see an image of the sheet here, the portions inside a yellow box are where I would like to have the automatic range function.

enter image description here

I am having a little trouble following along with your question and matching it up to the image you posted, but if I am understanding your question correctly and you are able to add a column (that is how I would do it) you could do something like the following:

I would add a column to go search for the text and get the row of cell the item was found on. So for example if you were searching for "A -20 Midds*" in column 'E', I would add a column between E&F that contained a formula as follows.

Formula starting on the new column F in cell F4:

=IFERROR(IF(SEARCH"A-20 Midds*",E4)>=1,ROW(E4),""),"")

This formula essentially is saying, find me "A-20 Midds*" and if you find it give me the row number that it is on, and if you do not find it leave it blank.

Once you have all of the row numbers you can use a variation of the INDIRECT function . So in this case you could use the following code as your range.

INDIRECT("E"&SMALL(F4:F25,1)&":F"&LARGE(F4:F25,1))

The "SMALL" function is looking for the smallest row number, which should be the row number that the text first appeared and the same for the "Large" number which should be the last row that the text appears, because you are getting the largest number.

Again this is my best guess based on my understanding of the question.

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