VBA Excel 2007 – Cells.Find

有人可以请解释如何阅读下面的代码find最后一列和数据行?

Last_Column = Sheets("Combined").Cells.Find("", [a1], , , xlByColumns, xlPrevious).Column Last_Row = Sheets("Combined").Cells.Find("", [a1], , , xlByRows, xlPrevious).Row 

谢谢

要find最后使用的列和行的相交点 ,您应该修改代码

  1. search"*"以匹配任何通配符而不是"" ,这是空白单元格(注意:如果您从combined表格中运行该代码,以上更改代码将在有限的意义上工作(请参阅下面的2-3)
  2. 不要假设表单有数据,即设置范围,然后testing它们是Not Nothing
  3. 当使用起始单元格时,例如'[a1]您应该指定表单名称以及如果您从不同的表单运行代码,例如ws.[a1]

     Sub FindLast() Dim ws As Worksheet Dim rng1 As Range Dim rng2 As Range Set ws = Sheets("combined") Set rng1 = ws.Cells.Find("*", ws.[a1], xlValues, , xlByRows, xlPrevious) Set rng2 = ws.Cells.Find("*", ws.[a1], xlValues, , xlByColumns, xlPrevious) If Not rng1 Is Nothing Then MsgBox "Last cell is " & Cells(rng1.Row, rng2.Column).Address(0, 0) Else MsgBox "No cells found" End If End Sub