Excel VBA Function runtime error 1004: Application-defined or object-defined error
- by music2myear
I'm trying to learn functions for the purpose of simplifying and reusing code whenever necessary.
I began by turning something I use pretty often into a function: Returning the integer value of the last non-blank row in a spreadsheet.
Function FindLastDataLine(strColName As String) As Long
FindLastDataLine = Range(strColName).Offset(Rows.Count - 1, 0).End(xlUp).Row
End Function
Sub PracticeMacro()
intItemCount = FindLastDataLine("A:A")
MsgBox ("There are " & intItemCount & " rows of data in column A.")
End Sub
When I run this I recieve the runtime error '1004' "Application-defined or object-defined error" which Help helpfully defines as "someone else's fault" to quote not quite verbatim.
Where might I be going wrong?