Complete a Range of cells using a formula to find address of last occupied cell

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
696
Office Version
  1. 2019
Platform
  1. Windows
Hello,
Looking to find the Last Occupied Cell to complete the Range of Cells in a formula.
Using 'Test' L:L. Replace the $J$27 with a formula to find the address of the last non-blank cell. ie $N$20, to complete the formula in L:L.
Thank you.


Wager History.xlsm
JKLMN
19G/L $RankTESTLast Non-Blankaddress of
20-$5.45554.55J27
21-$15.0066
22-$0.4533
23$4.5522
24$9.1011
25-$5.0044
26-$5.0044
27$4.5522
28   
29   
30   
31   
32   
33   
34   
35   
36   
37   
NBA Betting Ranks
Cell Formulas
RangeFormula
J20:J37J20=IF(K20<>"",(F20*4.55)-(G20*5),"")
K20:K37K20=IF(J20<>"",SUMPRODUCT((J20<=$J$20:$J$27)/COUNTIF($J$20:$J$27,$J$20:$J$27)),"")
L20:L37L20=IF(E20<>"",SUMPRODUCT((J20<=$J$20:$J$27)/COUNTIF($J$20:$J$27,$J$20:$J$27)),"")
M20M20=LOOKUP(2,1/(J20:J51<>""),J20:J51)
N20N20="J"&MATCH(2,1/(J:J<>""),1)
Press CTRL+SHIFT+ENTER to enter array formulas.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Using 'Test' L:L. Replace the $J$27 with a formula to find the address of the last non-blank cell. ie $N$20, to complete the formula in L:L.
To do that and use it will involve using volatile functions like INDIRECT as suggested above. I would be trying to avoid using volatile functions if possible.

What about something like this instead?

22 12 05.xlsm
JKL
19G/L $RankTEST
20($5.45)55
21($15.00)66
22($0.45)33
23$4.5522
24$9.1011
25($5.00)44
26($5.00)44
27$4.5522
TEST
Cell Formulas
RangeFormula
L20:L27L20=IF(E20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
 
Upvote 0
To do that and use it will involve using volatile functions like INDIRECT as suggested above. I would be trying to avoid using volatile functions if possible.

What about something like this instead?

22 12 05.xlsm
JKL
19G/L $RankTEST
20($5.45)55
21($15.00)66
22($0.45)33
23$4.5522
24$9.1011
25($5.00)44
26($5.00)44
27$4.5522
TEST
Cell Formulas
RangeFormula
L20:L27L20=IF(E20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
Hello,
I added your formula but I'm getting a decimal? Some values have been added, it done automatically.

Cell Formulas
RangeFormula
J20:J38J20=IF(E20<>"",(F20*4.55)-(G20*5),"")
K20:K38K20=IF(J20<>"",SUMPRODUCT((J20<=$J$20:$J$32)/COUNTIF($J$20:$J$32,$J$20:$J$32)),"")
L20:L32L20=IF(E20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
 
Upvote 0
I added your formula but I'm getting a decimal?
Yes, I forgot to allow for all the 'blank' formulas below your numerical data. Try this instead.

Excel Formula:
=IF(J20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)*(J$20:J$1000<>"")/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
 
Upvote 0
Yes, I forgot to allow for all the 'blank' formulas below your numerical data. Try this instead.

Excel Formula:
=IF(J20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)*(J$20:J$1000<>"")/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
Its still showing a decimal.
Cell Formulas
RangeFormula
J20:J35J20=IF(E20<>"",(F20*4.55)-(G20*5),"")
K20:K35K20=IF(J20<>"",SUMPRODUCT((J20<=$J$20:$J$32)/COUNTIF($J$20:$J$32,$J$20:$J$32)),"")
L20:L35L20=IF(J20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)*(J$20:J$1000<>"")/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
 
Upvote 0
Its still showing a decimal.
It is not for me - see below. However, I cannot replicate your sheet exactly as I do not have the data from columns E, F & G which are required to produce the column J values. So I have had to use the values as shown for J20:J32.

Can you post your mini sheet again after hiding columns H & I and then select E19:L35 to produce your mini sheet.
I suspect the issue has to do with rounding of decimal values.

gtd526.xlsm
JKL
19G/L $RankTEST
20($5.68)66
21($10.45)77
22$4.1033
23$4.5522
24$9.1011
25($1.35)44
26($5.00)55
27$4.1033
28($5.68)66
29($5.00)55
30($5.00)55
31($5.00)55
32$4.5522
33  
34  
35  
Sheet1
Cell Formulas
RangeFormula
J33:J35J33=IF(E33<>"",(F33*4.55)-(G33*5),"")
L20:L35L20=IF(J20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)*(J$20:J$1000<>"")/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
 
Upvote 0
It is not for me - see below. However, I cannot replicate your sheet exactly as I do not have the data from columns E, F & G which are required to produce the column J values. So I have had to use the values as shown for J20:J32.

Can you post your mini sheet again after hiding columns H & I and then select E19:L35 to produce your mini sheet.
I suspect the issue has to do with rounding of decimal values.

gtd526.xlsm
JKL
19G/L $RankTEST
20($5.68)66
21($10.45)77
22$4.1033
23$4.5522
24$9.1011
25($1.35)44
26($5.00)55
27$4.1033
28($5.68)66
29($5.00)55
30($5.00)55
31($5.00)55
32$4.5522
33  
34  
35  
Sheet1
Cell Formulas
RangeFormula
J33:J35J33=IF(E33<>"",(F33*4.55)-(G33*5),"")
L20:L35L20=IF(J20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)*(J$20:J$1000<>"")/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
Here's the sheet.

Cell Formulas
RangeFormula
D20:D37D20=IFERROR($F20+$G20,"")
E20:E37E20=IFERROR(LOOKUP(2, 1/((COUNTIF(E$19:$E19,'[My Wagers.xlsm]NBA'!$H$324:$H$501)=0)*('[My Wagers.xlsm]NBA'!$H$324:$H$501<>"")),'[My Wagers.xlsm]NBA'!$H$324:$H$501),"")
F20:F37F20=IFERROR(COUNTIFS('[My Wagers.xlsm]NBA'!$A$324:$A$501,"W",'[My Wagers.xlsm]NBA'!$H$324:$H$501,"<>",'[My Wagers.xlsm]NBA'!$H$324:$H$501,$E20)+$H20*0.5,"")
G20:G37G20=IFERROR(COUNTIFS('[My Wagers.xlsm]NBA'!$A$324:$A$501,"L",'[My Wagers.xlsm]NBA'!$H$324:$H$501,"<>",'[My Wagers.xlsm]NBA'!$H$324:$H$501,$E20)+$H20*0.5,"")
H20:H37H20=IF(E20<>"",COUNTIFS('[My Wagers.xlsm]NBA'!$A$324:$A$501,"Psh",'[My Wagers.xlsm]NBA'!$H$324:$H$501,"<>",'[My Wagers.xlsm]NBA'!$H$324:$H$501,$E20),"")
I20:I37I20=IFERROR($F20/($F20+$G20),"")
J20:J37J20=IF(E20<>"",(F20*4.55)-(G20*5),"")
K20:K37K20=IF(J20<>"",SUMPRODUCT((J20<=$J$20:$J$32)/COUNTIF($J$20:$J$32,$J$20:$J$32)),"")
L20:L37L20=IF(J20<>"",SUMPRODUCT(IFERROR((J20<=J$20:J$1000)*(J$20:J$1000<>"")/COUNTIF(J$20:J$1000,J$20:J$1000),0)),"")
 
Upvote 0
Here's the sheet.
Thanks. Unfortunately that doesn't allow me to fully check since some of those extra formulas that I can now see are drawing from another workbook that I cannot see.
However, I am now almost certain that the problem is related to rounding as I mentioned before.

The values that we can see in the mini sheet in column J are not the true underlying values in those cells. To demonstrate, below I have put the calculation part of the column J formulas in column N. You can see that the two yellow cells are not the same as what is showing in column J. I'm pretty sure that there is more than that though. What happens if you re-format columns F & G to show say 5 decimal places? Does it then show any different values in those columns compared to what we can see in your mini sheet above?

One more thing to test, in an empty cell, what does this formula return?
=COUNT(J20:J1000)

If nothing still stands out as a likely problem, what happens if you change the column J formula to this?
=IF(E20<>"",ROUND((F20*4.55)-(G20*5),2),"")

Cell Formulas
RangeFormula
J20:J33J20=IF(E20<>"",(F20*4.55)-(G20*5),"")
N20:N33N20=(F20*4.55)-(G20*5)
 
Upvote 0
Thanks. Unfortunately that doesn't allow me to fully check since some of those extra formulas that I can now see are drawing from another workbook that I cannot see.
However, I am now almost certain that the problem is related to rounding as I mentioned before.

The values that we can see in the mini sheet in column J are not the true underlying values in those cells. To demonstrate, below I have put the calculation part of the column J formulas in column N. You can see that the two yellow cells are not the same as what is showing in column J. I'm pretty sure that there is more than that though. What happens if you re-format columns F & G to show say 5 decimal places? Does it then show any different values in those columns compared to what we can see in your mini sheet above?

One more thing to test, in an empty cell, what does this formula return?
=COUNT(J20:J1000)

If nothing still stands out as a likely problem, what happens if you change the column J formula to this?
=IF(E20<>"",ROUND((F20*4.55)-(G20*5),2),"")

Cell Formulas
RangeFormula
J20:J33J20=IF(E20<>"",(F20*4.55)-(G20*5),"")
N20:N33N20=(F20*4.55)-(G20*5)
One more thing to test, in an empty cell, what does this formula return?
=COUNT(J20:J1000)
It returns 14.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,212
Members
453,023
Latest member
alabaz

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