There are a few things that are wrong with your code as it stands now:
- Properties can only be members of a class
- Variables are subject to what is known as scope, and specifically your two variables
numberOfColumns
andnumberOfRows
are only available within the scope of thetest()
Sub, so they and their values cannot be seen inside theHasNoData()
property unless they are passed as parameters or set as members of the class - The VBA
Msgbox
takes a String as the parameter, whereas you have provided a Boolean
I think what you really want is to make "HasNoData" into a function that takes two parameters, one for rows and one for columns. Try this:
Public Function HasNoData(NumRows, NumCols) As Boolean
HasNoData = (NumCols < 2 And NumRows < 2)
End Function
Sub test()
If HasNoData(3, 5) Then
MsgBox "There is data!"
Else
MsgBox "There is no data."
End If
End Sub