VBA类型运行时13错误

VBA类型运行时13错误,vba,excel,Vba,Excel,我想知道是否有人能帮我解决这个问题。我编写了一个宏,其目标是根据行中的所有单元格是否都包含值“删除选定行。您的测试表达式可能如下所示: Join(WorksheetFunction.Transpose(WorksheetFunction.Transpose(Range(Cells(i, FirstCol), Cells(i, LastCol)).Value)), " ") Like "*<0.01*" Join(工作表函数.Transpose(工作表函数.Transpose(范围(单元格

我想知道是否有人能帮我解决这个问题。我编写了一个宏,其目标是根据行中的所有单元格是否都包含值“删除选定行。您的测试表达式可能如下所示:

Join(WorksheetFunction.Transpose(WorksheetFunction.Transpose(Range(Cells(i, FirstCol), Cells(i, LastCol)).Value)), " ") Like "*<0.01*"

Join(工作表函数.Transpose(工作表函数.Transpose(范围(单元格(i,第一列)、单元格(i,最后列)).Value)),“”)如“*您可以使用每行的
Find
函数:

Dim FndRng  As Range

For i = rng To 1 Step -1
    Set FndRng = Range(Cells(i, FirstCol), Cells(i, LastCol)).Find(What:="<0.01", LookIn:=xlValues, LookAt:=xlWhole)
    If Not FndRng Is Nothing Then ' find was successful
        Rows(i).Delete
    End If
Next 
Dim FndRng作为范围
对于i=rng至1步骤-1

设置FndRng=Range(Cells(i,FirstCol),Cells(i,LastCol)).Find(What:=”您需要在列之间循环-您不能用字符串测试数组(例如
范围
值)。(您还应该检查循环计数器-您正在根据某个范围内的行数进行循环,但使用计数器引用工作表中的行。因此,如果您选择的范围是
A21:D30
,即10行,则您将检查工作表中的行10到1。)此外,即使标量到数组的比较有效(@YowE3K解释不会)您正在与字符串值进行比较,而不是numeric@avb我不认为OP是在测试<0.01的数字。问题的编写方式让我认为单元格中确实包含字符串
。”我想你是对的,如果是这样的话……您好。我正在搜索字符串OP需要一行中的所有单元格都等于“@EganWolf现在我明白他的意思了,谢谢。我会马上更新它!干得好:)@ShaiRado我尝试了您的解决方案,在运行时收到了一个类型13不匹配。完整代码如下:
Sub t()Dim rng As Range Dim firstcol,LastCol As Long Dim i As Range Set rng=应用程序。选择集i=rng。行firstcol=rng(1)。列LastCol=rng(rng.Cells.Count)。列i=rng到1步-1 If WorksheetFunction.CountIf(范围(单元格(i,firstcol),单元格(i,LastCol)),”@非常感谢你。效果很好。我不明白从最后一行减去1的必要性
LastRow=Rng.Rows.Count+firstRow-1
为什么这不仅仅是
Rng.Rows.Count
Dim FndRng  As Range

For i = rng To 1 Step -1
    Set FndRng = Range(Cells(i, FirstCol), Cells(i, LastCol)).Find(What:="<0.01", LookIn:=xlValues, LookAt:=xlWhole)
    If Not FndRng Is Nothing Then ' find was successful
        Rows(i).Delete
    End If
Next 
For i = rng To 1 Step -1
    If WorksheetFunction.CountIf(Range(Cells(i, FirstCol), Cells(i, LastCol)), "<0.01") = Range(Cells(i, FirstCol), Cells(i, LastCol)).Cells.Count Then
        Rows(i).Delete
    End If
Next I
Option Explicit

Sub t()

Dim Rng As Range
Dim firstCol As Long, LastCol As Long
Dim firstRow As Long, LastRow As Long
Dim i As Long
Dim C As Range

Set Rng = Selection ' only if you realy need to

' calculate the first and last column of the Selection
firstCol = Rng(1).Column
LastCol = Rng.Columns.Count + firstCol - 1

' calculate the first and last Row of the Selection
firstRow = Rng(1).Row
LastRow = Rng.Rows.Count + firstRow - 1

' loop backwards, for the Selection last row, until the first row of the selection
For i = LastRow To firstRow Step -1
    ' loop through current's row cells
    For Each C In Range(Cells(i, firstCol), Cells(i, LastCol))
        If C.Value2 <> "<0.01" Then
            GoTo ExitLoop
        End If
    Next C

    Rows(i).Delete

ExitLoop:
Next i

End Sub