Dynamic arrays and "loop" functions without using vba

Beinleif

New Member
Joined
Aug 3, 2020
Messages
3
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
I've been playing around with dynamic arrays and spill functions trying to find out a way to get the information seen in column H.
1596452561378.png

I have length data in column A and a data value in column B (could be anything, i.e height parameter, salinity, burial depth etc. at that specific length).
I want to look at the data in column B with a lower resolution than column A, hence the "step length". In column D and E I've simply marked the data that corresponds to a length <=2, <=4, <=6 .... <=2*n. Column H is the average of the data corresponding to the different length sections.
I tried to use the filter function =FILTER($B$2:B22;$A$2:A22<=D2) which spills the data with a length <=2 [m] in cells E2:E4 followed by =AVERAGE(E2#) in cell H2. This is however not a viable solution since the number of data points in each length section will vary. The actual length data in my case would be more like 0, 0.2, 0.21, 0.9, 1.8 etc. hence between 0 and 2 [m] there could be perhaps 12 rows of data and between 2 and 4 [m] there could be 3 rows of data. Since i don't know how many rows the filter function will spill in column E I can't manage to create column D.
Any advice on how to do this in excel without vba?

In vba I would have done something like;

lastrow=22 '(xlenduprow somethingsomething)
steplength=2
counter1=1
counter2=0
tempdata=0

for i=2 to lastrow

if cells(i,1)<=steplength then

tempdata=tempdata+cells(i,2)
counter2=counter2+1

else

newarray(counter1,1)=steplength*counter1-2 & "-" & steplength*counter1 '(same as column G. Could also just be counter1)
newarray(counter1,2)=tempdata/counter2 '(average data per length section, same as column H)
counter1=counter1+1
tempdata=0

end if

next
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Why not use a pivot table?
 
Upvote 0
I'm not sure if a pivot table would give me the flexibility I need. If only column A and B exists can a pivot table give me column G and H?
As far as I can see I can use column A as a filter in pivot and very manually select length = 0, 1 and 2 and get the corresponding average data from column B. However this is only one length section (0-2 [m]). How would i get access to all the length sections? I can't do that manually if column A goes from 0 to 10 000 [m].
When i have column G and H I want to further manipulate it. It could be graphs etc.
 
Upvote 0
You could add the Length column as a row item and average of Data as a data item then you can add grouping for the Length group.

It might not give you the exact results you've shown, but I'm not 100% sure how you arrived at those.

Book1
ABCDEF
1LengthDataRow LabelsAverage of Data
200.10-10.15
310.22-30.35
420.34-50.55
530.46-70.75
640.58-90.95
750.610-111.15
860.712-131.35
970.814-151.55
1080.916-171.75
119118-202
12101.1Grand Total1.1
13111.2
14121.3
15131.4
16141.5
17151.6
18161.7
19171.8
20181.9
21192
22202.1
Sheet1
 
Upvote 0
Ah, have not used the "grouping" in pivot table. That would give me column G and H, however the lower and upper limit in grouping seems to be like this:
lower<=data<upper but I can work with that. That is why your pivot table has slightly different avg data values than my spreadsheet.
Thank you for this solution:)
 
Upvote 0

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top