vba:查找最后一行失败,错误91 [英] vba: find last row fails with error 91
问题描述
我正在使用 http:// c厘米/ lastRow(sheet As Worksheet)As Long 如果工作表中包含某些东西,它可以工作。如果它是空的或内容失败,错误91(对象变量或块变量未设置)。 为什么? 考虑: I am using this code from http://ccm.net/faq/14494-vba-last-non-empty-row-all-versions It works if the sheet contains something. If it is empty or has had content it fails with error 91 (object variable or with block variable not set). Why ? Consider:
这篇关于vba:查找最后一行失败,错误91的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
lastRow = sheet.Columns(1).Find(*,,,,xlByColumns,xlPrevious).Row
结束函数
function lastRow(sheet As Worksheet)As变量
Dim r As Range,lr As Long
设置r = sheet.Columns(1).Find(*,,,,xlByColumns,xlPrevious)
如果r是Nothing Then
lastRow =列中没有
Else
lastRow = r.Row
如果
结束函数
Function lastRow(sheet As Worksheet) As Long
lastRow = sheet.Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row
End Function
Function lastRow(sheet As Worksheet) As Variant
Dim r As Range, lr As Long
Set r = sheet.Columns(1).Find("*", , , , xlByColumns, xlPrevious)
If r Is Nothing Then
lastRow = "Nothing in column"
Else
lastRow = r.Row
End If
End Function