判断到哪里结束应该是Excel VBA最常见的操作之一,下面代码能实现这个功能:

 

 
  
  1. Function LastColumn() As Long     
  2.     Dim ix As Long 
  3.     ix = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count 
  4.     LastColumn = ix   
  5. End Function 
  6.  
  7.  
  8. Function LastRow() As Long 
  9.     Dim ix As Long 
  10.     ix = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count 
  11.     LastRow = ix 
  12. End Function 

 

 

ref:

http://excelvbamacro.com/how-to-find-the-last-row-that-contain-data-in-excel.html

http://excelvbamacro.com/get-position-of-last-column-containing-data-with-excel-vba.html