vba Sub FindLastRowWithUsedRange() Dim ws As Worksheet Set ws = ActiveSheet Dim lastRow As Long With ws lastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row End With MsgBox "最后一行的行号是: " & lastRow End Sub
示例代码 05Sub Find_LastRowxlFormulas()On Error GoTo Finish'获取最后一行MsgBox &qu 8、ot;最后一行是第 " & Cells.Find("*", _ SearchOrder:=xlByRows, LookIn:=xlFormulas, _ SearchDirection:=xlPrevious).EntireRow.Row &行 ”“Exit Sub Finish:MsgBox "没发现数值或公式! "End Sub 下面再列举...
打开Excel文件并按下Alt + F11,打开Visual Basic for Applications(VBA)编辑器。 在VBA编辑器中,选择插入(Insert)-> 模块(Module),创建一个新的模块。 在新的模块中,输入以下代码: 代码语言:txt 复制 Function FindLastRow(sheetName As String) As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets(sh...
Public Function LastRow() As Long '本代码包含隐藏行 '使用常量xlFormulas,因为常量xlValues会忽略隐藏的最后一行 LastRow = Cells.Find("*", LookIn:=xlFormulas, SearchDirection:=xlPrevious).Row End Function 注:Find方法中,参数LookIn的默认值为xlFormulas。 --- 使用SpecialCells方法SpecialCells方法用于查找指定...
MsgBox "数据单元格的最大行号: " &Cells.Find("*", , , , 1, 2).Row MsgBox "数据单元格的最大列号: " &Cells.Find("*", , , , 2, 2).Column End Sub ★★ Find 常常与FindNext配合使用,下一次再学习FindNext吧! ===有时用以下代码==【收藏】 ...
[ 示例代码 04] Sub Find_LastRowxlValues() On Error GoTo Finish 获取最后一行 MsgBox 最后一行是第 Cells.Find(*, _ SearchOrder:=xlByRows, LookIn:=xlValues, _ SearchDirection:=xlPrevious).EntireRow.Row “行” Exit Sub Finish: MsgBox 没有发现数值! End Sub 因此,在使用 Find方法时, 您应该...
LastRow = ix EndFunction 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. ref: http:///how-to-find-the-last-row-that-contain-data-in-excel.html http:///get-position-of-last-column-containing-data-with-excel-vba.html
SubFind_LastRowxlValues() OnErrorGoToFinish '获取最后一行 MsgBox"最后一行是第"&Cells.Find("*",_ SearchOrder:=xlByRows,LookIn:=xlValues,_ SearchDirection:=xlPrevious).EntireRow.Row&“行” ...
Find and Delete Outlook Calendar Item using VBA Find last row of an excel spreadsheet using vba in access Force an Export to XLSX Format Forecasting in access form opens too big Form will not open in Form View, but open in Design and Layout View Format Numeric 9(8)V99 FORMATING OUTPUT ...
参数RowAbsolute设置为True,则返回的地址行部分为绝对引用。默认值为True。 参数ColumnAbsolute设置为True,则返回的地址的列部分为绝对引用。默认值为True。 参数ReferenceStyle设置返回的地址的引用样式,可以设置为xlA1(A1样式)或xlR1C1(R1C1样式)。默认值为xlA1。