Vba计算行并将行数返回到消息框

时间:2015-01-27 07:55:27

标签: excel vba

我正在使用excel。我有一个搜索按钮,让我假设我搜索并找到3条记录。

我想知道的是:如何显示在消息框中找到的记录数量?

1 个答案:

答案 0 :(得分:0)

这应该有用吗?

Sub Msg_exe()  
result = MsgBox("Found values:", yourValue)
End Sub  

您只需将变量传递给文本框功能:)

对于行计数,有几种方法可以做到:

Sub FindingLastRow()

Dim sht As Worksheet
Dim LastRow As Long

Set sht = ThisWorkbook.Worksheets(Sheet1.Name)

'Ctrl + Shift + End
  LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

'Using UsedRange
  LastRow = sht.UsedRange.Rows.Count

'Using Table Range
  LastRow = sht.ListObjects("Table1").Range.Rows.Count

'Using Named Range
  LastRow = sht.Range("MyNamedRange").Rows.Count

'Ctrl + Shift + Down (Range should be first cell in data set)
  LastRow = sht.Range("A1").CurrentRegion.Rows.Count

End Sub