Invalid Use of Property when Calling public Function

Viewed 31

I'm trying to code a very simple little function in VBA for Excel and it has not gone well. I don't have consistent access to Excel so I can only work on it here and there. Debugging has been hell and only managed to get it working through the VBA Excel editor by creating a sub and running it through that. I've only started using VBA the last few weeks and am well out of my depth here so I'm probably missing something quite obvious any help with any part of this would be welcome

Public Function CellColorer(ByRef dayNo As Range)
Dim checkDate As Date
Dim table1 As ListObject

    table1 = ActiveWorkbook.Sheets("Sheet1").ListObjects("Table1")
    checkDate = CDate(CStr(dayNo.Range(1, 1).Value) + CStr(Evaluate(ActiveWorkbook.Names("MoMonth"))) + CStr(Evaluate(ActiveWorkbook.Names("MoYear"))))
    
    Dim i As Integer
    For i = 1 To table1.ListRows.Count
        If table1.DataBodyRange(i, 1) < checkDate & table1.DataBodyRange(i, 2) > checkDate Then
            Application.ThisCell.Interior.Color = table1.DataBodyRange(i, 1).Interior.Color
            CELLCOLOURER = ""
            Return
        ElseIf table1.DataBodyRange(i, 1) = checkDate Then
                Application.ThisCell.Interior.Color = table1.DataBodyRange(i, 1).Interior.Color
                CELLCOLOURER = table1.DataBodyRange(i, 0) + "START!"
                Return
        ElseIf table1.DataBodyRange(i, 2) = checkDate Then
                Application.ThisCell.Interior.Color = table1.DataBodyRange(i, 1).Interior.Color
                CELLCOLOURER = table1.DataBodyRange(i, 0) + "DUE!"
                Return
    Next i

End Function
Sub jili() 'I'm using this code to debug I couldn't figure out how to do so without it
CellColorer (ActiveWorkbook.Worksheets(2).Range("E6"))
End Sub

The main goal of the code is too check a date specified by the user between a start date and end date. If it is in the inclusive range it should change the cells color to match that tables color as well as displaying some text if it's the start or the end of the project.

0 Answers
Related