VSTO 获取sheet单元格行列数
1 Public Sub Igor() 2 Dim Dtsheet As Excel.Worksheet 3 Dim TotalC As Long '原始数据范围列 4 Dim TotalR As Long '原始数据范围行 5 Dtsheet = Globals.ThisWorkbook.Sheets("sheet1") 6 TotalC = Dtsheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Column 7 TotalR = Dtsheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row 8 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) 9 10 End Sub