Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 选择介于第3行和第2行到最后一行之间的范围运行时错误13:类型不匹配?_Excel_Vba - Fatal编程技术网

Excel 选择介于第3行和第2行到最后一行之间的范围运行时错误13:类型不匹配?

Excel 选择介于第3行和第2行到最后一行之间的范围运行时错误13:类型不匹配?,excel,vba,Excel,Vba,我试图编写一个代码,首先查找最后一行,然后选择第二行到最后一行和第三行之间的所有行。然后继续删除它们。但我一直遇到一个错误13:类型不匹配 Dim StartRow, LastRow, NuRow As Variant StartRow = 3 Sheets("Sheet3").Activate If WorksheetFunction.CountA(Cells) > 0 Then 'Search for any entry, by searching backw

我试图编写一个代码,首先查找最后一行,然后选择第二行到最后一行和第三行之间的所有行。然后继续删除它们。但我一直遇到一个错误13:类型不匹配

  Dim StartRow, LastRow, NuRow As Variant
  StartRow = 3
  Sheets("Sheet3").Activate
  If WorksheetFunction.CountA(Cells) > 0 Then

    'Search for any entry, by searching backwards by Rows.

   LastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows,  SearchDirection:=xlPrevious).Row
End If
    NuRow = LastRow - 1
    Rows("StartRow:NuRow").Delete 'Run time error 13 Type Mismatch
有什么想法吗?

试试这个:

Rows(StartRow & ":" & NuRow).Delete
Rows(StartRow & ":" & NuRow).Delete

抛出错误的是Rows对象。它需要一个格式为“3:20”的行索引(例如)。您正在传递字符串“StartRow:NuRow”

尝试将该语句更改为: