ヒント:他の言語はGoogle翻訳されています。 訪問することができます English このリンクのバージョン。
ログイン
x
or
x
x
お申し込み
x

or

Excelのセル値に基づいて行を自動ろ過する方法は?

通常、Excelのフィルタ機能は必要なデータをフィルタリングするのに役立ちますが、手動セル入力に基づいてセルを自動フィルタリングすることがあります。これは、セルに条件を入力すると、データを一度に自動的にフィルタリングされます。 この仕事をExcelで処理するための良いアイデアはありますか?

VBAコードで入力したセルの値に基づいて行を自動フィルタリングする

大文字と小文字の区別による、テキスト長などの複数の条件またはその他の特定の条件によるデータのフィルタリング


VBAコードで入力したセルの値に基づいて行を自動フィルタリングする


以下のデータ範囲があるとします.E1とE2セルに条件を入力すると、以下のスクリーンショットのようにデータが自動的にフィルタ処理されます。

docオートフィルター1

1。 入力したセルの値に基づいて日付を自動フィルター処理するワークシートに移動します。

2。 シートタブを右クリックして、 コードを表示 コンテキストメニューから、ポップアウトされた アプリケーション用Microsoft Visual Basic 次のコードをコピーして空白に貼り付けてください モジュール ウィンドウ、スクリーンショットを参照してください:

VBAコード:入力されたセル値に従ってデータを自動フィルタリングする:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160606
   If Target.Address = Range("E2").Address Then
       Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
   End If
End Sub

docオートフィルター2

:上記のコードでは、 A1:C20 フィルタリングするデータ範囲です。 E2 に基づいてフィルタリングするターゲット値です。 E1:E2 あなたの基準セルは、に基づいてフィルタリングされます。 必要に応じて変更することができます。

3。 今、あなたがセルの基準を入力すると E1 そして E2 を押し 入力します キーを押すと、データはセル値によって自動的にフィルタリングされます。


大文字と小文字の区別による、テキスト長などの複数の条件またはその他の特定の条件によるデータのフィルタリング

テキストの長さ、大文字と小文字の区別など、複数の条件またはその他の特定の条件によるデータのフィルタリング

Kutools for Excelさん スーパーフィルター 機能は強力なユーティリティです。この機能を適用すると、次の操作を完了できます。

  • 複数の基準でデータをフィルタリングする。 テキストの長さでデータをフィルタリングする。
  • 大文字/小文字のデータをフィルタリングする。 年/月/日/週/四半期のフィルタリングの日付

doc-super-filter1

Kutools for Excel200便利なExcelアドイン以上で、60日に制限なく試してみることができます。 今すぐダウンロードして無料トライアル!


デモ:VBAコードで入力したセルの値に基づいて行を自動フィルタする


Kutools for Excel-最高のOffice生産性向上ツールにより、生産性が80%向上

  • 再利用: すばやく挿入 複雑な数式、チャート そして、以前に使用したもの; セルを暗号化する パスワード付き メーリングリストの作成 そしてメールを送る...
  • スーパーフォーミュラバー (複数行のテキストや数式を簡単に編集する) レイアウトを読む (多数のセルを簡単に読んで編集できます)。 フィルター範囲に貼り付ける...
  • セル/行/列を結合 データを失うことなく; セルコンテンツの分割。 重複する行/列を結合する...重複セルの防止。 範囲の比較...
  • 重複または一意を選択します空白行を選択 (すべてのセルは空です)。 スーパー検索とファジー検索 多くのワークブックで。 ランダム選択
  • 完全コピー 式の参照を変更せずに複数のセル。 参照を自動作成 複数のシートに 箇条書きを挿入、チェックボックスなど
  • テキストを抽出、テキストの追加、位置による削除、 スペースを削除する; ページング小計の作成と印刷 セルのコンテンツとコメント間の変換...
  • スーパーフィルター (保存して他のシートにフィルタ方式を適用する)。 高度な並べ替え 月/週/日、頻度などによる。 特殊フィルター 太字、斜体で...
  • ワークブックとワークシートを組み合わせる; キー列に基づいて表をマージします。 データを複数のシートに分割する; xls、xlsx、およびPDFのバッチ変換...
  • 300を超える強力な機能。 Office / Excel 2007-2019および365をサポートします。 すべての言語をサポートします。 企業または組織に簡単に展開できます。 フル機能の60日間の無料トライアル。
KTEタブ201905

OfficeタブはOfficeにタブ付きインターフェイスを提供し、作業をより簡単にします

  • Word、Excel、PowerPointでタブ付き編集と読み取りを有効にする、出版社、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を50%向上させ、毎日数百回のマウスクリックを削減します。
オフィシタブ底
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    tim · 1 months ago
    Hey guys,
    perfect Explanation, thank you very much.
    1 Little question: if I want to filter with 2,3 4 or more criterias how do I do this?
    For example I want to say I wanna see the Name Henry, with Grade 1 and this Age...so not just 1 criteria but for example 3..=?


    thanks for the respond


    Kind regards,


    TIM
    • To post as a guest, your comment is unpublished.
      skyyang · 1 months ago
      Hi, tim,
      To auto filter data based on multiple criteria, you should apply the below code: (please change the cell references to your need)

      Private Sub Worksheet_Change(ByVal Target As Range)
      'Update by Extendoffice
      Dim xVStr As String
      Dim xFStr As String
      xVStr = "E22:G22" 'the criteria that you want to filter based on
      xFStr = "E21:G22" 'the range contains the header of the criteria
      If Not (Intersect(Range(xVStr), Target) Is Nothing) Then
      Range("A1:C17").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, _
      CriteriaRange:=Range(xFStr)
      End If
      End Sub


      Please try, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Bogdan · 2 months ago
    Hello,

    What if I got the filtered data in a different tab(sheet 2) in the same workbook and the cell that the filter needs to refer to is in the first tab(sheet 1). I used this VBA but is not working like that, only if I have both the criteria cell(E2 in this VBA) in the same tab with the filtered data(A1:C20)
  • To post as a guest, your comment is unpublished.
    mjr_awesome · 2 months ago
    There might be a mistake in the instructions. Instead of pasting the code into a blank Module, one should paste it into the Sheet window. For example, if the macro is to work on Sheet1, the code should be pasted into Microsoft Excel Objects -> Sheet1(Sheet1). Only then it works for me on Excel 2016.

    Thanks for the code!
    • To post as a guest, your comment is unpublished.
      skyyang · 2 months ago
      Hi, mjr,
      There is no mistake in this article, the article said, you should put the VBA code into the sheet module by right click the sheet name and then choose View Code to go to the module.
      But, your operation is correct as well.
      Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Robert · 7 months ago
    So I have a bunch of values and then a table of data. I am wondering if I can filter that table based on the values similarly to what is explained above. For example I would like to click on a cell that has the value of 3, which corresponds to 3 records(200 rows, 25 columns) that meet a condition and then have my table filtered to just show those records. An example of a condition would be, if one variable is great than 100. I have over 100 of these conditions which is why I would like my table to be linked to it in some way. Any help would be much appreciated. In your example provided, it would be similar to if you just wanted all ages over 3, 6, 9, 12 etc and then you had 25 similar variables.So to filter the table to show only records with age over 3 based on clicking a value from a list that says something like age>3 - 2 records, age>6 - 4 records etc
  • To post as a guest, your comment is unpublished.
    Elliott · 7 months ago
    Is there a way to have it continue to filter with additional boxes. When I write it as ElseIf, it only follows the ElseIf command.
  • To post as a guest, your comment is unpublished.
    murat yazici · 8 months ago
    Private Sub Worksheet_Change(ByVal Target As Range)
    'Updateby Extendoffice 20160606
    If Target.Address = Range("E2").Address Then
    Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
    End If
    End Sub


    E2 HUCRESI YERINE E SUTUNUNUNA YAZILAN SON SATIRA GORE FILITRELEME YAPABILIR MI


    According the code mentioned above , is it possible to make filtration according the written data to the last row of column E ?


    I hope to get help and thanks for your help
    • To post as a guest, your comment is unpublished.
      skyyang · 8 months ago
      Hi, murat,
      The above code works well in the whole worksheet, you just need to change the cell references to your need. Please try it, thank you!
  • To post as a guest, your comment is unpublished.
    Kent · 8 months ago
    The VB script worked beautifully. Many thanks for the post!
  • To post as a guest, your comment is unpublished.
    Bob · 8 months ago
    What happens if you have GRADE11 and GRADE12 for example. Will the filter show these also if you try and filter
    on GRADE1?
    • To post as a guest, your comment is unpublished.
      skyyang · 8 months ago
      Hello, Bob,
      Yes, as you said, when entering part of the text you want to filter, all the cells contain the part text will be filtered out. So, if you type Grade1, all cells contain Grade1, Grade11, Grage123...will be filtered out.
  • To post as a guest, your comment is unpublished.
    Mark · 9 months ago
    Thank you for this code. I have been trying to modify it to work better for me, but having difficulty.

    My sheet has data from A2:G2280 Column A contains street names. I want to be able to type at least part of the street name into A1 and display only data that contains A1 in all or part. So if I type Bro in A1 I would see the rows that have Broad, Broadway and Brook. Of course if A1 is blank I would see everything.



    Sorry I'm not fluent in the Excel VBA lingo, I'm just a 911 dispatcher that knows their is an easier way.



    Thank you.



    Mark
    • To post as a guest, your comment is unpublished.
      skyyang · 9 months ago
      Hello, Mark,
      To solve your problem, please apply the following VBA code:
      Note: In the below code, the A1 is the cell that you want to enter the criteria, A2:D20 is the data range, A is the column contains the criteria that you want to filter from, please change the cell references to your own.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg As Range
      Dim xRRg As Range
      Dim xFNum As Integer
      On Error Resume Next
      If Target.Address <> Range("A1").Address Then Exit Sub
      Set xRg = Range("A2:D20").CurrentRegion
      Application.ScreenUpdating = False
      If Target.Text = "" Then
      xRg.Rows.Select
      Selection.EntireRow.Hidden = False
      Application.ScreenUpdating = True
      Exit Sub
      End If
      For xFNum = 1 To xRg.Rows.Count
      Set xRRg = xRg.Range("A" & xFNum)
      xRRg.Rows.Select
      If InStr(xRRg.Text, Target.Text) > 0 Then
      Selection.EntireRow.Hidden = False
      Else
      Selection.EntireRow.Hidden = True
      End If
      Next xFNum
      Application.ScreenUpdating = True
      End Sub

      Please try it, hope it can help you!
      • To post as a guest, your comment is unpublished.
        Mark · 9 months ago
        Thanks for the help.
        I changed A2:D20 to A3:G2281 to represent my data field. Now when I type anything in cell A1 and tab out of the cell rows 2-109 are hidden. It is not filtering and displaying only rows that contain all or in part what is entered in cell A1.



        Any ideas?
  • To post as a guest, your comment is unpublished.
    shahbaaz · 11 months ago
    its working and awsome...thanks
  • To post as a guest, your comment is unpublished.
    George · 1 years ago
    Thank you for this write up! I am trying to adjust the code to allow a range of acceptance.

    Example: I input 5 and it filters and only shows everything that is within .5 of 5, (so 4.5 to 5.5)
  • To post as a guest, your comment is unpublished.
    Javier · 2 years ago
    Doesn't work for me, might be that I have office 2010? doesn't do anything :S
  • To post as a guest, your comment is unpublished.
    Amanda · 2 years ago
    Hi,

    The code below works perfectly. However, how do I disable the macro if I want to unfilter?
    Private Sub Worksheet_Change(ByVal Target As Range)
    'Updateby Extendoffice 20160606
    If Target.Address = Range("E2").Address Then
    Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
    End If
    End Sub
    • To post as a guest, your comment is unpublished.
      KST · 1 years ago
      In Range("E2").Address delete any input. All will "unfilter."
  • To post as a guest, your comment is unpublished.
    ZZted · 2 years ago
    How do I undo it?it hides all of my data.
  • To post as a guest, your comment is unpublished.
    jdvdp · 2 years ago
    I've been trying to filter a worksheet with a variety of codes (taken from various sites, including this one), but none seem to work. In a sheet with information in the cell range A101:EF999 (yes, big one), I want to autofilter the sheet based on a three letter code that I enter into cell B5, which should correspond to rows having that same code in column B101-B999. A sample snippet would look like this:

    A B C D E
    5 ABC
    ...
    101 ABC
    102 DEF
    103 GHI
    104 ABC
    105 JKL
    106 ABC
    107 DEF

    On selecting "ABC" in cell B5, only rows 101, 104 and 106 should be displayed, but nothing happens. Is there something I'm overlooking here? Any help would be much appreciated!
  • To post as a guest, your comment is unpublished.
    Jon · 2 years ago
    THANK YOU SO MUCH FOR THE ABOVE FORMULA - IT WORKS GREAT.