第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Excel VBA自動(dòng)過(guò)濾除三個(gè)以外的所有內(nèi)容

Excel VBA自動(dòng)過(guò)濾除三個(gè)以外的所有內(nèi)容

大話西游666 2020-02-03 12:40:54
在我的數(shù)據(jù)分析的持續(xù)傳奇中(第一個(gè)問(wèn)題),我想刪除部門(字段7)不是101、102或103(名稱已更改以保護(hù)無(wú)辜)的所有行。數(shù)據(jù)中大約有一百個(gè)部門,因此使用Criteria1:=Array("104", "105", "106",etc是不切實(shí)際的。我想做這樣的事情:myrange.AutoFilter Field:=7, Criteria1:="<>101", Operator:=xlOr, _    Criteria2:="<>102", Operator:=xlOr, Criteria3:="<>103"但Excel識(shí)別的標(biāo)準(zhǔn)不超過(guò)2個(gè)。我可以添加一個(gè)幫助器列,并使宏遍歷每行(如果是101、102或103,則value = Yes),過(guò)濾出yes,然后刪除所有剩余的內(nèi)容,但我將其保存為最后采取。有沒(méi)有辦法使自動(dòng)篩選條件1不等于數(shù)組?就像是:myrange.AutoFilter Field:=7, Criteria1:="<>" & Array("101", "102", "103")
查看完整描述

3 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊

記住目標(biāo)是刪除不匹配的行;自動(dòng)篩選只是幫助實(shí)現(xiàn)該目標(biāo)的一種工具。如果自動(dòng)篩選不能滿足您的需求,請(qǐng)選擇其他方法??紤]:


Sub AllBut()

    Dim rTable As Range, r As Range

    Dim rDelete As Range

    Set rTable = Selection

    Set rDelete = Nothing

    For Each r In rTable.Columns(7).Cells

        v = r.Value

        If v <> "101" And v <> "102" And v <> "103" Then

            If rDelete Is Nothing Then

                Set rDelete = r

            Else

                Set rDelete = Union(r, rDelete)

            End If

        End If

    Next


    If Not rDelete Is Nothing Then rDelete.EntireRow.Delete

End Sub

在這里,我們選擇要處理的數(shù)據(jù)塊(不包括標(biāo)題行)。宏向下掃描該塊的第7列,并刪除任何不符合條件的行。


剩下的將是101、102和103。


查看完整回答
反對(duì) 回復(fù) 2020-02-03
?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊

由于這是關(guān)于AutoFilter方法的,因此我將提供這種方法,其中涉及使用Scripting.Dictionary對(duì)象來(lái)模擬在工作表上手動(dòng)執(zhí)行該過(guò)程。


在工作表上,用戶將應(yīng)用“自動(dòng)篩選”,然后使用G列的下拉菜單“關(guān)閉” 101、102和103值。剩下的將被刪除。在VBA中,我們可以獲取所有G列,并使用非101、102或103的值填充字典對(duì)象,并將其用作過(guò)濾操作的標(biāo)準(zhǔn)。


Sub filterNotThree()

    Dim d As Long, dDELs As Object, vVALs As Variant


    Set dDELs = CreateObject("Scripting.Dictionary")


    With Worksheets("Sheet6")

        If .AutoFilterMode Then .AutoFilterMode = False

        With .Cells(1, 1).CurrentRegion

            'grab all of column G (minus the header) into a variant array

            vVALs = .Resize(.Rows.Count - 1, 1).Offset(1, 6).Value2


            'populate the dictionary object with the values that are NOT 101, 102, or 103

            For d = LBound(vVALs, 1) To UBound(vVALs, 1)

                Select Case vVALs(d, 1)

                    Case 101, 102, 103

                        'do not add

                    Case Else

                        'not a match, add it to the delete list

                        'the AutoFilter criteria needs to be text

                        ' so we set the Keys as text and the Items as numbers

                        dDELs.Item(CStr(vVALs(d, 1))) = vVALs(d, 1)

                End Select

            Next d


            'check to make sure there is something to filter on

            If CBool(dDELs.Count) Then

                'filter on the dictionary keys

                .AutoFilter field:=7, Criteria1:=dDELs.keys, Operator:=xlFilterValues


                'delete the visible rows (there has to be some)

                .Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0).EntireRow.Delete

            End If


        End With

        If .AutoFilterMode Then .AutoFilterMode = False

    End With


    dDELs.RemoveAll: Set dDELs = Nothing

End Sub


查看完整回答
反對(duì) 回復(fù) 2020-02-03
?
慕虎7371278

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊

我在做類似的事情,但在兩個(gè)領(lǐng)域,這種語(yǔ)法對(duì)我有用:


myrange.AutoFilter Field:=7, Criteria1:="<>101", Operator:=xlAnd, Criteria2:="<>102", Operator:=xlAnd

希望能幫助到你。


查看完整回答
反對(duì) 回復(fù) 2020-02-03
  • 3 回答
  • 0 關(guān)注
  • 928 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)