删除当前行vba

时间:2017-08-02 06:09:53

标签: excel vba excel-vba

问题:

我需要删除不符合我条件的行。

代码:

假设所有值都已初始化。

        preparedStatement = connection.prepareStatement(insertTableSQL,PreparedStatement.RETURN_GENERATED_KEYS);
        preparedStatement.setString(1, id);

        preparedStatement .executeUpdate();
        primaryKeyResultset= preparedStatement.getGeneratedKeys();
        if(primaryKeyResultset.next()){
            generatedId= primaryKeyResultset.getLong(1);
        }

我尝试了什么:

For ind = 2 To lrow reportProcess = Trim(LTrim(RTrim(ws.Range("G" & ind).Text))) If reportProcess = "Fulfillment - H/W Direct Customers (Operational)" Or reportProcess = "Revenue - Hardware" Then brand = "HW" ElseIf reportProcess = "Revenue - Software" Then ' ~~ Check Control Point Number subReportProcess = Mid(ws.Range("I" & ind).Text, 12, 3) If subReportProcess = "201" Or subReportProcess = "202" Or subReportProcess = "203" Or subReportProcess = "204" Or subReportProcess = "205" Then brand = "PBS" Else brand = "SWG" End If ElseIf reportProcess = "Revenue - GBS" Or reportProcess = "Revenue - GTS IS" Or reportProcess = "Fulfillment - Services(Operational)" Then brand = "PBS" ElseIf reportProcess = "Revenue - TSS" Then brand = "TSS" ElseIf reportProcess = "Accounts Receivable" Or reportProcess = "IBM Credit LLC - Accounts Receivable" Then brand = "AR" End If country = Trim(LTrim(RTrim(ws.Range("V" & ind).Text))) If country = "Taiwan" Then geo = "Taiwan" ElseIf country = "India" Then geo = "India" ElseIf country = "New Zealand" Or country = "Australia" Then geo = "ANZ" ElseIf country = "Hong Kong" Then geo = "Hong Kong" ElseIf country = "Philippines" Or country = "Malaysia" Or country = "Singapore" Or country = "Thailand" Or country = "Vietnam" Or country = "Indonesia" Then geo = "ASEAN" Else ' ~~ INSERT DELETE ROW HERE End If ws.Range("B" & ind) = geo ws.Range("A" & ind) = brand Next ind - 但这会删除所有行

ActiveCell.EntireRow.Delete - 与上述结果相同

如何使用循环删除特定的行号?

2 个答案:

答案 0 :(得分:2)

您需要遍历从最后一行到第一行的列表。如果不这样做,您将跳过删除行之后的下一行。注意:这也适用于从列表框,组合框和集合中删除项目。

For ind = lrow To 2 Step -1
    reportProcess = Trim(LTrim(RTrim(ws.Range("G" & ind).Text)))
    If reportProcess = "Fulfillment - H/W Direct Customers (Operational)" Or reportProcess = "Revenue - Hardware" Then
        brand = "HW"
    ElseIf reportProcess = "Revenue - Software" Then
        ' ~~ Check Control Point Number
        subReportProcess = Mid(ws.Range("I" & ind).Text, 12, 3)
        If subReportProcess = "201" Or subReportProcess = "202" Or subReportProcess = "203" Or subReportProcess = "204" Or subReportProcess = "205" Then
            brand = "PBS"
        Else
            brand = "SWG"
        End If
    ElseIf reportProcess = "Revenue - GBS" Or reportProcess = "Revenue - GTS IS" Or reportProcess = "Fulfillment - Services(Operational)" Then
        brand = "PBS"
    ElseIf reportProcess = "Revenue - TSS" Then
        brand = "TSS"
    ElseIf reportProcess = "Accounts Receivable" Or reportProcess = "IBM Credit LLC - Accounts Receivable" Then
        brand = "AR"
    End If

    country = Trim(LTrim(RTrim(ws.Range("V" & ind).Text)))
    If country = "Taiwan" Then
        geo = "Taiwan"
    ElseIf country = "India" Then
        geo = "India"
    ElseIf country = "New Zealand" Or country = "Australia" Then
        geo = "ANZ"
    ElseIf country = "Hong Kong" Then
        geo = "Hong Kong"
    ElseIf country = "Philippines" Or country = "Malaysia" Or country = "Singapore" Or country = "Thailand" Or country = "Vietnam" Or country = "Indonesia" Then
        geo = "ASEAN"
    Else
        ' ~~ INSERT DELETE ROW HERE
        ws.Rows(ind).Delete Shift:=xlUp
    End If
    ws.Range("B" & ind) = geo
    ws.Range("A" & ind) = brand
Next ind

我根据@ShaiRado建议重构了OP的代码。

For ind = lrow To 2 Step -1
    reportProcess = Trim(LTrim(RTrim(ws.Range("G" & ind).Text)))
    Select Case reportProcess
    Case "Fulfillment - H/W Direct Customers (Operational)", "Revenue - Hardware"
        brand = "HW"
    Case "Revenue - Software"
        ' ~~ Check Control Point Number
        subReportProcess = Mid(ws.Range("I" & ind).Text, 12, 3)
        If subReportProcess = "201" Or subReportProcess = "202" Or subReportProcess = "203" Or subReportProcess = "204" Or subReportProcess = "205" Then
            brand = "PBS"
        Else
            brand = "SWG"
        End If
    Case "Revenue - GBS", "Revenue - GTS IS", "Fulfillment - Services(Operational)"
        brand = "PBS"
    Case "Revenue - TSS"
        brand = "TSS"
    Case "Accounts Receivable", "IBM Credit LLC - Accounts Receivable"
        brand = "AR"
    End Select

    country = Trim(LTrim(RTrim(ws.Range("V" & ind).Text)))
    Select Case country
    Case "Taiwan"
        geo = "Taiwan"
    Case "India"
        geo = "India"
    Case "New Zealand", "Australia"
        geo = "ANZ"
    Case "Hong Kong"
        geo = "Hong Kong"
    Case "Philippines", "Malaysia", "Singapore", "Thailand", "Vietnam", "Indonesia"
        geo = "ASEAN"
    Case Else
        ' ~~ INSERT DELETE ROW HERE
        ws.Rows(ind).Delete Shift:=xlUp
    End Select

    ws.Range("B" & ind) = geo
    ws.Range("A" & ind) = brand
Next ind

答案 1 :(得分:0)

请尝试以下代码:

<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs/clientphp"
ServerName clientphp
SSLEngine on
SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
<Directory "C:/xampp/htdocs/clientphp">
    Options All
    AllowOverride All
    Require all granted
</Directory>