删除不符合VBA标准

时间:2015-08-13 19:52:00

标签: excel vba excel-vba

我有许多工作表,其序列线性xy数据的长度不同。目标是删除x数据不能被50整除的所有行。下面是生成的宏,它使用辅助列来搜索要删除的整数。

    Sub Divis50()

    Sheets("VERT SCALES").Select
    Range("C2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF((OR((RIGHT(RC[-2],2)=""50""),(RIGHT(RC[-2],2)=""00""))),""YES"",""NO"")"
    Range("C2").Select
    Selection.AutoFill Destination:=Range("C2:C6062")

    'sort filtered results
    Range("C2").Select  
    ActiveWorkbook.Worksheets("VERT SCALES").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("VERT SCALES").Sort.SortFields.Add Key:=Range("C2") _
        , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("VERT SCALES").Sort
        .SetRange Range("A2:C6062")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

    ' scroll to first no and delete rows
    Rows("123:123").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents

    'sort "A" back to consecutive numbers
    Range("A2").Select
    ActiveWorkbook.Worksheets("VERT SCALES").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("VERT SCALES").Sort.SortFields.Add Key:=Range("A2") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("VERT SCALES").Sort
        .SetRange Range("A2:C122")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

    'delete filtered column
    Columns("C:C").Select
    Selection.Delete Shift:=xlToLeft
End Sub

2 个答案:

答案 0 :(得分:1)

这将删除除以50

时不等于整数的行
class SmImageHandlerController{

    public function test($param) {
        return $param;
    }
}

答案 1 :(得分:0)

我建议使用帮助列来适当标记数据。通过公式或VB。 然后使用自动过滤器选择标志,然后删除。

在这里尝试删除过滤数据的示例代码。 http://www.mrexcel.com/forum/excel-questions/460513-visual-basic-applications-code-delete-only-rows-filtered.html