Excel VBA Function runtime error 1004: Application-defined or object-defined error

Posted by music2myear on Super User See other posts from Super User or by music2myear
Published on 2011-06-23T21:47:20Z Indexed on 2011/06/24 0:25 UTC
Read the original article Hit count: 238

Filed under:
|
|

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?

© Super User or respective owner

Related posts about microsoft-excel

Related posts about vba