I am building a function, that when you select a cell, the output is the cell range from the selection to the last filled cell row on the same column.
Here is the code, that works perfectly.
''Get the cell range from selection to last cell
Function CellRange(CellA As Range)
CellRange = CellA.Address + ":" + CellA.End(xlDown).Address
End Function
QUESTION: I want to update this code, so that when used for dates, the user can filter with three options: YTD (year to date), ALL (all time - i.e. getting all data), a year (i.e. 2015 / 2014 / 2013 etc.)
My end goal is for the user to select a cell in a range column of dates and input YTD or ALL or a given year (i.e. 2014) and get the range with his filter.
EXAMPLE: The user writes =cellrange(A2,2014)
, which should yield $A$2:$A$23
and if the user changes to =cellrange(A2,2014)
this should yield $A$24:$A$40
as seen on the image.
I tried various loops or counts but I feel quite lost as none of my tries apparently made any sense.
I am looking for some help: guidance or a solution to the problem preferably, as I want to build up on it after I tackle this one (hence why I am doing it on VBA).
=cellrange(A9, 2014)
, should it return$A$2:$A$23
or does it return$A$9:$A$23
? – basodrecellrange(A9, 2014)
it will be best to return$A$2:$A$23
– Newskooler