Skip formula over blank cells (VBA or Excel Functions)

jacc99

New Member
Joined
Jun 14, 2021
Messages
12
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. MacOS
Hi guys,
Firstly apologies i don't have any example code or functions to show you where i am at atm, as i am very lost with regards to this particular situation.
I really just want to know if this is actually possible using VBA or some collection of excel functions.
Effectively i have a column of prices and a column of returns calculated at the moment as IFERROR(LN(t+1/t),""). This is fine when there is back to back prices in the column, however when there is a missing value for t+1 it obviously still tries to calculate the return with the missing value. This can be seen in the first set of 'Current' Columns.
My desired outcome is that excel recognises when there is a blank cell in t+1, and skips over it to the next available cell with a price in it. This can be seen in the 'desired' columns. I.e. if t+1 is blank, skip to t+2 or t+n and calculate the RTN as LN(t+n/t). It should then carry on as usual calculating Ln(t+1/t).
I hope that makes some sense. fairly confusing to articulate. Again im more interested in knowing if this is possible rather than having a respondent do the code or functions for me.

Many thanks



Book2
XYZAAABACADAE
139416
139417CurrentDesired
139418PricesRTNPricesRTN
139419.702.702
139420.70185-0.021%.70185-0.021%
139421.701870.003%.701870.003%
139422.701890.003%.701890.003%
139423.701960.010%.701960.010%
139424.701990.004%.701990.004%
139425.70195-0.006%.70195-0.006%
139426.701960.001%.701960.001%
139427  
139428.70198 .701980.003%
139429.70197-0.001%.70197-0.001%
139430.701970.000%.701970.000%
139431  
139432  
139433.70189 .70189-0.011%
139434.70185-0.006%.70185-0.006%
139435.701850.000%.701850.000%
139436.701870.003%.701870.003%
139437.70165-0.031%.70165-0.031%
139438.701770.017%.701770.017%
139439.70175-0.003%.70175-0.003%
139440
1 Min Closing data 2019 - 2Min
Cell Formulas
RangeFormula
Z139420:Z139439,AC139420:AC139427,AC139429:AC139432,AC139434:AC139439Z139420=IFERROR(LN(Y139420/Y139419),"")
AC139428AC139428=IFERROR(LN(AB139428/AB139426),"")
AC139433AC139433=IFERROR(LN(AB139433/AB139430),"")
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Put in an IF statement [ if the cell above is Blank, then pull the cell 2 above it, Else use 1 cell above). In my example, I used Y10 as my starting range, then in cell Z11 i have the following formula
Excel Formula:
=IF(Y10="",IFERROR(LN(Y11/Y9),""),IFERROR(LN(Y11/Y10),""))
I'm having it test if the cell above is blank and if it is, it will then grab the cell 2 above it, otherwise it is your normal formula.
The other option is to remove the blanks and copy formula downward.
 
Upvote 0
Hi Jacc99,

I can do it with a worker column.

Jacc99-2.xlsx
YZAAAB
139417CurrentWorker
139418PricesRTN0
1394190.702 0.702
1394200.70185-0.021%0.70185
1394210.701870.003%0.70187
1394220.701890.003%0.70189
1394230.701960.010%0.70196
1394240.701990.004%0.70199
1394250.70195-0.006%0.70195
1394260.701960.001%0.70196
139427 0.70196
1394280.701980.003%0.70198
1394290.70197-0.001%0.70197
1394300.701970.000%0.70197
139431 0.70197
139432 0.70197
1394330.70189-0.011%0.70189
1394340.70185-0.006%0.70185
1394350.701850.000%0.70185
1394360.701870.003%0.70187
1394370.70165-0.031%0.70165
1394380.701770.017%0.70177
1394390.70175-0.003%0.70175
Sheet1
Cell Formulas
RangeFormula
Z139419:Z139439Z139419=IFERROR(LN(Y139419/AB139418),"")
AB139419:AB139439AB139419=IF(Y139419<>"",Y139419,AB139418)
 
Upvote 0
Hey @Toadstool & @queuesmef
thanks a lot for your input, i will give both methods a go and try to implement them I really appreciate you giving some examples. Just quickly, i have added a further example below with 2 missing cells, would the methods you show work if there were two or three or n missing cells?
thanks a lot!

Book2
XYZAAABACADAE
139416
139417CurrentDesired
139418PricesRTNPricesRTN
139419.702.702
139420.70185-0.021%.70185-0.021%
139421.701870.003%.701870.003%
139422.701890.003%.701890.003%
139423.701960.010%.701960.010%
139424.701990.004%.701990.004%
139425.70195-0.006%.70195-0.006%
139426.701960.001%.701960.001%
139427  
139428.70198 .701980.003%
139429.70197-0.001%.70197-0.001%
139430.701970.000%.701970.000%
139431  
139432  
139433  
139434.70185 .70185-0.017%
139435.701850.000%.701850.000%
139436.701870.003%.701870.003%
139437.70165-0.031%.70165-0.031%
139438.701770.017%.701770.017%
139439.70175-0.003%.70175-0.003%
139440
1 Min Closing data 2019 - 2Min
Cell Formulas
RangeFormula
Z139420:Z139439,AC139420:AC139427,AC139429:AC139432,AC139435:AC139439Z139420=IFERROR(LN(Y139420/Y139419),"")
AC139428AC139428=IFERROR(LN(AB139428/AB139426),"")
AC139433AC139433=IFERROR(LN(AB139433/AB139430),"")
AC139434AC139434=IFERROR(LN(AB139434/AB139430),"")
 
Upvote 0
Hey @Toadstool & @queuesmef
thanks a lot for your input, i will give both methods a go and try to implement them I really appreciate you giving some examples. Just quickly, i have added a further example below with 2 missing cells, would the methods you show work if there were two or three or n missing cells?
thanks a lot!

Book2
XYZAAABACADAE
139416
139417CurrentDesired
139418PricesRTNPricesRTN
139419.702.702
139420.70185-0.021%.70185-0.021%
139421.701870.003%.701870.003%
139422.701890.003%.701890.003%
139423.701960.010%.701960.010%
139424.701990.004%.701990.004%
139425.70195-0.006%.70195-0.006%
139426.701960.001%.701960.001%
139427  
139428.70198 .701980.003%
139429.70197-0.001%.70197-0.001%
139430.701970.000%.701970.000%
139431  
139432  
139433  
139434.70185 .70185-0.017%
139435.701850.000%.701850.000%
139436.701870.003%.701870.003%
139437.70165-0.031%.70165-0.031%
139438.701770.017%.701770.017%
139439.70175-0.003%.70175-0.003%
139440
1 Min Closing data 2019 - 2Min
Cell Formulas
RangeFormula
Z139420:Z139439,AC139420:AC139427,AC139429:AC139432,AC139435:AC139439Z139420=IFERROR(LN(Y139420/Y139419),"")
AC139428AC139428=IFERROR(LN(AB139428/AB139426),"")
AC139433AC139433=IFERROR(LN(AB139433/AB139430),"")
AC139434AC139434=IFERROR(LN(AB139434/AB139430),"")
Apologies, i have just noticed my original example already included two missing cells!
 
Upvote 0
Apologies, i have just noticed my original example already included two missing cells!
Yes, you can use exactly the same formulae. Column AB is just bridging any gaps so it just carries the previous value down if column Y has gaps, whether it's 1 cell or 20 cells of gaps.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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