怎么知道最后一行填满vba(excel)? [英] how to know the last row filled in vba (excel)?
本文介绍了怎么知道最后一行填满vba(excel)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格调用Recap,我想知道我在这张表中有多少行。我尝试使用这段代码:
I have a sheet calls "Recap" and I want to know how much line that I have in this sheet.I tried with this code:
Function FindingLastRow(Mysheet As String) As Long
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ThisWorkbook.Worksheets(Mysheet)
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
FindingLastRow = LastRow
End Function
......
在我的宏我尝试这样:
....
Dim lastR As Long
lastR=FindingLastRow("Recap")
msgBox lastR
...
推荐答案
您正在将一个字符串传递到您的 FindingLastRow
函数中没有使用它。 shiit 是传入的参数,但您稍后尝试使用名为 Mysheet 的东西。
You are passing a string into your FindingLastRow
function but are not using it. shiit is the parameter being passed in but you later try to use something called Mysheet.
Function FindingLastRow(Optional MySheet As String, Optional sCOL as String = "A") As Long
Dim sht As Worksheet
Dim LastRow As Long
If Not CBool(Len(MySheet)) Then MySheet = ActiveSheet.Name
Set sht = ThisWorkbook.Worksheets(MySheet)
LastRow = sht.Cells(sht.Rows.Count, sCOL).End(xlUp).Row
FindingLastRow = LastRow
Set sht = nothing
End Function
Sub test_FindingLastRow()
Dim lastR As Long
lastR = FindingLastRow
MsgBox lastR
lastR = FindingLastRow("Recap")
MsgBox lastR
lastR = FindingLastRow("Recap", "B")
MsgBox lastR
End Sub
如果没有传递工作表名称,则使用当前ActiveSheet的名称。如果没有传递字母列名,它将使用列A。
If no worksheet name is passed in then the currently ActiveSheet's name is used. If no alphabetic column name is passed in it will use column A.
这篇关于怎么知道最后一行填满vba(excel)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文