At start you declared you need to select 30 cells, now it is 140 cells!?
OK! Let's it be 140 (or less, as you can't select 140 cells with your conditions, when you are e.g. on row 10).
Define a dynamic range (Main Menu>Formulas>Name Manager) e.g. dnRange140 as
Code:
=OFFSET(YourSheetName!$A$1,MAX((ROW()-140)-1,0),,MAX(MIN((ROW()),140),1),1)
Now you can use this dynamic name a reference, which returns a range of cells depending on your active row number, and ending at your active row. P.e. when you enter into D1 the formula =COUNT(dnRange140), and copy it down to D173, the returned values start from 1 in first row to 140 in 140 row, and remains 140 after that. In case you activate a cell in row 169, the number of cells in dnRange140 is 140, and the returned range is A29:A169.
Edit. When you activate any cell on this sheet, then open Name Manager from menu, activate this Named Range, and then click on Refers To field, the current range of it will be marked as active on your sheet - so you can see which cells are included at this moment.