我在VB 2017上使用VB.NET
我想从Excel电子表格中检索范围。
在工作表的某处,有一个名称为"纬度"的单元格,在该单元格下的单元格中,存在未确定的纬度数字。
我找到包含"纬度"的单元格的位置。使用此代码的字符串:
Dim LatitudeCell = ExcelWorksheet.Cells.Find("latitude")
我不知道如何获取该单元格下方所有数字的范围,因为我不知道有多少行包含数据。
答案 0 :(得分:1)
Dim LastCell as Range
Dim FullRange as Range
Set LastCell = LatitudeCell.End(xlDown)
Set FullRange = Range(LatitudeCell.Offset(1,0), LastCell)
这是VBA中的代码。 VB.Net也是如此,只是枚举器xlDown可能需要根据.Net库进行限定。
在VB.NET中是
Imports Microsoft.Office.Interop
Dim LastCell As Excel.Range
Dim FullRange As Excel.Range
LastCell = LatitudeCell.End(Excel.XlDirection.xlDown)
FullRange = ExcelWorksheet.Range(LatitudeCell.Offset(1, 0), LastCell)