I have created a function which has 4 parameters: SearchDate, StartDate, EndDate, Events. The way I wanted the function to work was if the SearchDate is >= for some start date and =< for some end date then the function pulls the events name. For example, if the search was June 17 and the start/end date was June 15/June 18 then it would pull the event.
However the code doesn't seem to work; when I try to use it gives me a value error. I have posted the code and a table, that the function is based on, below.
Function Calendar_Events(SearchDate As Date, StartColumn As Range, EndColumn As Range, EventsColumn As Range)
Dim x As Long
Dim output As Range
For x = 1 To StartColumn.Cells.CountLarge
If Int(StartColumn.Cells(x)) <= SearchDate And Int(EndColumn.Cells(x)) >= SearchDate Then
'in place for the case of more events then rows
If y >= 3 Then
output = output & "........"
Exit For
End If
output = output & Left(EventsColumn.Cells(x), 20) & vbNewLine
y = y + 1
End If
Next x
End Function
Table:
Start Date End Date Event
1/12/2018 1/19/2018 Software Sale
1/31/2018 1/31/2018 Dinner Party
2/1/2018 2/1/2018 Baby Shower
2/12/2018 2/16/2018 Team Retreat
2/15/2018 2/16/2018 Bank Meetings
2/15/2018 2/15/2018 Lunch Date
2/15/2018 2/15/2018 Dinner Date
3/26/2018 3/29/2018 Vacation
3/28/2018 3/29/2018 Swimming
3/28/2018 3/28/2018 Mountain Biking
3/29/2018 3/29/2018 Put away clothes
3/29/2018 4/4/2018 Cottage
4/2/2018 4/2/2018 Family Photo
4/2/2018 4/4/2018 Software Sale
4/2/2018 4/6/2018 Hire Nanny
4/6/2018 4/6/2018 Day Off
StartDate
a Range of multiple cells? If nothing else, that's a bad name for that variable, because it's not properly descriptive. Further, you should provide some example data so that others can more easily assist you. This is known as a minimal reproducible example and is part of How to Ask a good question – David ZemensStartColumn
andEndColumn
orStartRange
, etc., rather thanStartDates
, etc. – David ZemensCalendar_Events = output
to return the value. To debug your function, call it from a Sub, not from a worksheet cell. – Tim Williams