VSTO 获取sheet单元格行列数

时间:2023-03-09 22:59:35
VSTO 获取sheet单元格行列数
     Public Sub Igor()
Dim Dtsheet As Excel.Worksheet
Dim TotalC As Long '原始数据范围列
Dim TotalR As Long '原始数据范围行
Dtsheet = Globals.ThisWorkbook.Sheets("sheet1")
TotalC = Dtsheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Column
TotalR = Dtsheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row
Dtsheet.Range("A1", Dtsheet.Cells(TotalR, TotalC)).Replace(What:="", Replacement:="N/A", LookAt:=Excel.XlLookAt.xlWhole, SearchOrder:=Excel.XlSearchOrder.xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False) End Sub