为什么我使用If Not Range.Value在vba中收到类型不匹配错误?

时间:2015-12-11 03:36:48

标签: excel vba excel-vba

我试图删除列" A"中值的所有行。不符合以下字段格式(1)7位数字,(2)姓氏,名字,(3)日期......或以下值(4)不适用(5)输出。

第9行继续抛出#34; Type Mismatch"错误。有什么想法吗?

Public Sub DeleteRows()
Dim RowToTest As Long

Call setVariables   '***sets wsName variable

    'Code to delete unneeded rows based on cell value in Column "A"
    For RowToTest = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
        With ActiveWorkbook.Worksheets(wsName).Cells(RowToTest, 1)
                If Not .Value Like "???????" Or "*[,]*" Or "*?[/]*?[/]*??" _
                  Or "?????[:]*" Then
                    If Not .Value = "INPATIENT" Or "OUTPATIENT" Then
                        Rows(RowToTest).EntireRow.Delete
                    End If
                End If
        End With
    Next RowToTest
End Sub

2 个答案:

答案 0 :(得分:3)

你的功能应如下所示:

<ItemGroup>
    <OutputFiles1 Include="Project1\bin\Release\*.*" />
    <OutputFiles2 Include="Project2\bin\Release\*.*" />
</ItemGroup>

<Target CopyOutput>
    <Copy SourceFiles="@(OutputFiles1)" DestinationFolder="DeployOutput" />
    <Copy SourceFiles="@(OutputFiles2)" DestinationFolder="DeployOutput" />
</Target>

答案 1 :(得分:2)

使用它:

If Not .Value Like "???????" And _
     Not .Value Like "*[,]*" And _
       Not .Value Like "*?[/]*?[/]*??" And _
         Not .Value Like "?????[:]*" And _
       .Value <> "INPATIENT" And _
     .Value <> "OUTPATIENT" Then
    Rows(RowToTest).EntireRow.Delete
End If