我一直在嘗試各種方法來查找範圍中的最後一行並將此數字返回給子例程,但無濟於事。Excel 2011 VBA - 自定義函數來獲取最後一行的範圍
下面的代碼我有
Sub StartHere()
Dim oSheet As Worksheet
Set oSheet = WorkSheets(1)
ProcessData(oSheet)
End Sub
Sub ProcessData(ByVal wkst As Worksheet)
Dim rng As Range
Dim lastRow As Long
'set range
Set rng = wkst.Range("L:S") 'Range that i want to process data on
'get the last row (in Long datatype)
lastRow = CLng(getLastRowInRange(rng))
End Sub
Function getLastRowInRange(ByRef rng As Range)
getLastRowInRange = rng.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows,_ SearchDirection:=xlPrevious).Row
End Function
我一直在
getLastRowInRange = rng.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows,_ SearchDirection:=xlPrevious).Row
任何線索,讓球員類型不匹配?
可能的重複[如何查找包含Excel中的數據的宏的最後一行?](http://stackoverflow.com/questions/71180/how-can-i-find-last-row-包含數據在Excel中的表格與宏) – GSerg
嗨GSerg,不,它不是重複的。當我單獨嘗試getLastRowInRange函數時沒有問題,但是當我將它與StartHere()和ProcessData()子例程集成時遇到了問題。所以我想弄清楚我的代碼有什麼問題。 – Poliquin
好的。然後看到我的答案。 – GSerg