Count Rows

TexEth

New Member
Joined
Jan 24, 2023
Messages
22
Office Version
  1. 365
Platform
  1. Windows
I need your help with VB code.

Data:
Columns: A to Z
Rows: 1 to 30

Task:
1). Count: Number of rows between the minimum value and the last row. Do for each column.
2). Match (find): The FIRST value AFTER the minimum value, which is >= to the initial value in the column (e.g., A2, B2, etc.).
2). Count: Number of rows between the minimum value and the first value, which is >= to the first value in the column (e.g., A2, B2, etc.)

Return:
Place the results in the bottom three empty rows.

Thank you.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I did it with array formulas and lets.

Mr Excel Questions.xlsx
ABCDEF
2
31219391380432383
4717115514023131366
512668455453661324
612727871015532486
7131914983635201066
81117944107810211362
992175487910181304
106718733001498704
1194091250414791494
1235312436341340612
13147513546831041357
14509930708645484
151153510115312921208
161154372921525390
1784692111787571184
18461129411611339887
19141913359651244731
2010689536651208688
219111460665394506
228004631489898787
2331535914561155833
2431913011209485995
25108511758133881159
269005641031520309
271304125541411111463
284741434710617870
291250129213548351077
30680956453436996
311245137510964451001
32824562119614191325
33
34Min Value in Column315
35Rows Col Min To End10
36Next Greater Value After Min Value1245
37Rows Min Value to the 2nd Greatest Value In The Column From Top18
38
39
CountRows
Cell Formulas
RangeFormula
B34B34=LET(c, B3:B32, cmin, MIN(B3:B32),cmin)
B35B35=LET( c,B3:B32,cMin,MIN(c), cMinToEnd,B32:INDEX(B3:B32,MATCH(cMin,B3:B32,0)), CountRowsMinToEnd, COUNT(cMinToEnd),CountRowsMinToEnd)
B36B36=LET( init,B3,c,B3:B32,cMin,MIN(c), rMinPlus1ToEnd,B32:INDEX(B3:B32,1+MATCH(cMin,B3:B32,0)), INDEX(rMinPlus1ToEnd, XMATCH(0.0001, (rMinPlus1ToEnd)*(--(rMinPlus1ToEnd>=init)),1,-1)))
B37B37=LET( init,B3,c,B3:B32,cMin,MIN(c), rMinTo2ndFrTop,B4:INDEX(B3:B32,MATCH(cMin,B3:B32,0)-1), locNextLargestAfter1st,XMATCH(0.000001,(rMinTo2ndFrTop)*(--(rMinTo2ndFrTop>=init)),1), COUNT(INDEX(rMinTo2ndFrTop,locNextLargestAfter1st):INDEX(B3:B32,MATCH(cMin,B3:B32,0)-1)) )
 
Upvote 0
The counting of the two rows formula did not work for me. The other two formula codes are working. Please see the sample data.
 

Attachments

  • Capture_A.PNG
    Capture_A.PNG
    19.2 KB · Views: 6
Upvote 0
Can you give me the examples of what you should see using the data in my worksheet snippet? In the first column?
 
Upvote 0
I am confused with your requirements statements and with what you have in the initial post.
Instead of this:
1). Count: Number of rows between the minimum value and the last row. Do for each column.
do you mean this:
1). Count: Number of rows between the minimum value and the FIRST row. Do for each column.

and instead of this:
2). Count: Number of rows between the minimum value and the first value, which is >= to the first value in the column (e.g., A2, B2, etc.)
you mean this:
2). Count: Number of rows between the minimum value and the first value, which is >= to the MINIMUM value in the column and >= the first value in the column and AFTER the minimum value
 
Upvote 0
1) Count the rows between the second row (A2) and the minimum value in column A.
I start counting with the 2nd row because the first row is my header row!

2). Count the rows between the minimum value and the next (following) value that is equal to or greater than the initial value (i.e., A2).
The >= A2 value I am interested in should come AFTER the minimum value.
[Here, I am interested to know how long it takes me to rebound to the initial value after hitting rock bottom.]
[Rows represent time.]

Did you see the sample data I posted?

Thank you for your time!
 

Attachments

  • Capture_A.PNG
    Capture_A.PNG
    19.2 KB · Views: 4
Upvote 0
How does this look? There are discrepancies in how you count the Top To Min, the first column you include either the top or minimum cell. The rest seems okay. I have not read all of your last message as I post this, I hope I have not missed something.

Mr Excel Questions.xlsx
ABCDE
1YearDallasAustinHouston
220004007001000
320014257101020
420024507201040
520034757301060
620045007401080
720055257501100
820065507601120
920075754251140
1020083004601160
1120093504951180
1220104005301200
1320114505651220
1420125006001240
1520135506351260
162014600670800
172015650705875
182016700740950
1920177507751025
20
21300425800Minimum Value
229714Time Between Initial Value and Minimum Value
234007051025First Value after mininum which is >= initial value
24283Number of years between minimum value and recovery value
25
26300425800
279815
284007051025
29283
CountRows OP Data
Cell Formulas
RangeFormula
A2:A18A2=SEQUENCE(17,1,2000,1)
B26:D26B26=LET(c,B$2:B$19,cmin,MIN(c ),cmin)
B27:D27B27=LET( c,B$2:B$19, t,B$2, b,B$19, cmin,MIN(c), MinCellRef, INDEX(c,MATCH(cmin,c,0),1), TopToMin,t:MinCellRef, COUNT(TopToMin) )
B28:D28B28=LET( c,B$2:B$19, t,B$2, b,B$19, cmin,MIN(c), MinCellRef, INDEX(c,MATCH(cmin,c,0),1), MinToBot,b:INDEX(c,MATCH(cmin,c,0),1), NextLrgHigherThanInit, INDEX(MinToBot,XMATCH(0.00001,MinToBot*(--(MinToBot>=t)),1,1),1), NextLrgHigherThanInit )
B29:D29B29=LET( c,B$2:B$19, t,B$2, b,B$19, cmin,MIN(c), MinCellRef, INDEX(c,MATCH(cmin,c,0),1), MinToBot,b:INDEX(c,MATCH(cmin,c,0),1), NextLrgHigherThanInit, INDEX(MinToBot,XMATCH(0.00001,MinToBot*(--(MinToBot>=t)),1,1),1), COUNT(MinCellRef:NextLrgHigherThanInit)-1 )
Dynamic array formulas.
 
Upvote 0
=LET( c,B$2:B$19, t,B$2, b,B$19, cmin,MIN(c), MinCellRef, INDEX(c,MATCH(cmin,c,0),1), MinToBot,b:INDEX(c,MATCH(cmin,c,0),1), NextLrgHigherThanInit, INDEX(MinToBot,XMATCH(0.00001,MinToBot*(--(MinToBot>=t)),1,1),1), COUNT(MinCellRef:NextLrgHigherThanInit)-1 )
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,349
Members
449,155
Latest member
ravioli44

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