删除物料清单中的行

时间:2015-12-04 11:27:06

标签: vba solidworks

我目前正在尝试制作可以过滤我的BOM(物料清单)表的宏,但它会不断收到错误消息。

目标是删除包含文本的所有行"否"在9栏中,有人可以帮我这个吗?

2001:4E8::4001::::/64

2 个答案:

答案 0 :(得分:1)

bevare这会删除所有“no”行..就像Nothing nohere No NO no如果你想找不到那个独立然后在“no”的每一侧的代码中添加空格 - > “不”

Option Compare Text
Sub deleter()
Dim xrow As Long
Dim lastrow As Long

lastrow = Cells(65000, 9).End(xlUp).Row + 1
xrow = 1

Do
    If Not InStr(1, Cells(xrow, 9).Value, "No") = 0 Then
        Cells(xrow, 9).EntireRow.delete
    Else
        xrow = xrow + 1
    End If
Loop Until xrow = lastrow
End Sub

如果您需要使用大写字母查找“否”,请随意删除“选择比较文字dombine”选项 希望我帮忙

答案 1 :(得分:0)

这是我使用过的可能有用的代码。如果有装配级BOM,它将起作用。

Option Explicit

Sub main()

    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swFeat As SldWorks.Feature
    Dim swSubFeat As SldWorks.Feature
    Dim swBomFeat As SldWorks.BomFeature


    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swFeat = swModel.FirstFeature

    Do While Not swFeat Is Nothing
        If swFeat.GetTypeName2() = "TableFolder" Then
            Set swSubFeat = swFeat.GetFirstSubFeature
            Do While Not swSubFeat Is Nothing
                If swSubFeat.GetTypeName2() = "BomFeat" Then
                    Set swBomFeat = swSubFeat.GetSpecificFeature2()
                    Call ProcessBomFeature(swBomFeat)
                End If
                Set swSubFeat = swSubFeat.GetNextFeature()
            Loop
        End If
        Set swFeat = swFeat.GetNextFeature
    Loop
End Sub

Sub ProcessBomFeature(swBomFeat As SldWorks.BomFeature)

    Dim vTableArr As Variant
    Dim vTable As Variant
    Dim swTable As SldWorks.TableAnnotation

    vTableArr = swBomFeat.GetTableAnnotations()

    For Each vTable In vTableArr
        Set swTable = vTable
        Call ProcessTableAnn(swTable, swBomFeat.Configuration)
    Next vTable

End Sub

Sub ProcessTableAnn(swTableAnn As SldWorks.TableAnnotation, ConfigName As String)

    Dim nNumRow As Long
    Dim J As Long

    nNumRow = swTableAnn.RowCount
    Dim swBOMTableAnn As BomTableAnnotation
    Set swBOMTableAnn = swTableAnn

    For J = 0 To nNumRow - 1
        Dim bomCellText As String
        bomCellText = swTableAnn.DisplayedText(J, 9)
        If bomCellText = "No" Then
            swTableAnn.DeleteRow (J)
        End If
    Next J
End Sub