メインコンテンツへスキップ

Excelで2つの日付間のすべてのレコードを抽出するにはどうすればよいですか?

Author: Sun Last Modified: 2025-08-06

Excelでタイムスタンプ付きの大量のデータを扱う際、特定の2つの日付の間に該当するすべてのレコードを抽出したりフィルタリングしたりする必要がよくあります。例えば、請求期間内の取引を分析したり、特定の月の出勤記録を確認したり、カスタムな日付範囲内で記録された項目を調べたりすることが考えられます。関連する行を手動で検索しコピーするのは、特にデータ量が増えるにつれて、非常に面倒でエラーが発生しやすい作業です。2つの指定された日付間のすべてのレコードを効率的に抽出することは、大幅な時間と労力の節約だけでなく、重要なエントリを見逃す可能性やデータ処理中にミスを引き起こすリスクも低減します。

A screenshot of data range in Excel for extracting records between two dates Arrow right A screenshot showing extracted records between two dates in Excel

以下では、Excelで2つの日付間のすべてのレコードを抽出するためのいくつかの実用的な方法を紹介します。各アプローチは、数式ベースの抽出(アドイン不要)からKutools for Excelを使用した利便性の向上、VBAコード、そしてExcelの組み込みフィルターまで、異なるニーズやユーザーの好みに合わせた柔軟なソリューションを提供します。

数式を使用して2つの日付間のすべてのレコードを抽出する

Kutools for Excelを使用して2つの日付間のすべてのレコードを抽出する good idea3

VBAを使用して2つの日付間のレコードを抽出する

Excelフィルターを使用して2つの日付間のレコードを抽出する


数式を使用して2つの日付間のすべてのレコードを抽出する

Excelで数式を使用して2つの日付間のすべてのレコードを抽出するには、以下の手順に従います。この解決策は、元のデータセットまたは日付条件が変更されるたびに結果が自動的に更新されるため、動的な更新が必要な場合に特に有用です。ただし、配列数式に不慣れな場合、初期設定が少し複雑に感じるかもしれません。データセットが非常に大きい場合、この方法では計算パフォーマンスが低下する可能性があります。

1. 新しいワークシート(例: Sheet2)を準備し、そこで日付の範囲を指定し、抽出されたレコードを表示します。セルA2およびB2にそれぞれ開始日と終了日を入力します。明確にするために、A1およびB1にヘッダー(「開始日」や「終了日」など)を追加しても良いでしょう。
A screenshot of the start and end date input cells in Excel

2. Sheet2のセルC2に、Sheet1で指定された範囲内にある日付を持つ行数をカウントする次の数式を入力します:

=SUMPRODUCT((Sheet1!$A$2:$A$22>=A2)*(Sheet1!$A$2:$A$22<=B2))

数式を入力した後、 Enterキーを押します。これにより、フィルター条件に一致するエントリの数がわかるため、期待される結果の数を簡単に把握できます。
A screenshot of the formula used to count matching rows between two dates

注意: この数式では、Sheet1は元のデータシートを指します。$A$2:$A$22はデータ内の日付列です。これらの参照は、必要に応じてデータに合わせて調整してください。A2およびB2は開始日と終了日のセルです。

3. 一致するレコードを表示するには、抽出されたリストを開始したい空白のセルを選択します(例: Sheet2のセルA5)。次に、次の配列数式を入力します:

=IF(ROWS(A$5:A5)>$C$2,"",INDEX(Sheet1!A$2:A$22,SMALL(IF((Sheet1!$A$2:$A$22>=$A$2)*(Sheet1!$A$2:$A$22<=$B$2),ROW(Sheet1!A$2:A$22)-ROW(Sheet1!$A$2)+1),ROWS(A$5:A5))))

数式を入力した後、 Ctrl + Shift + Enter を押します(単にEnterではなく)。これにより、配列数式として機能します。その後、データの列数に応じて右方向にドラッグし、一致するすべての行が表示されるまで下方向にドラッグします。空白が表示され始めたら、それはすべての一致するデータが抽出されたことを意味します。
A screenshot showing the extracted data using formulas

ヒント:

  • ゼロが表示された場合、一致するレコードがそれ以上存在しないことを意味します。これ以上ドラッグを続ける必要はありません。
  • 数式のINDEX(...)部分を他の列を抽出するために適応できます。他のフィールドを返したい場合は、Sheet1!A$2:A$22部分の参照列を変更してください。
  • この数式は、複数の条件で動作するように拡張でき、または各行全体を抽出するために(各列で数式を繰り返すことによって)使用できます。

4. 日付結果の一部が5桁の数字(Excelのシリアル日付番号)として表示されることがあります。これを読みやすい日付形式に変換するには、対応するセルを選択し、「ホーム」タブを開き、書式設定のドロップダウンメニューから「短い日付」を選択します。これにより、抽出されたデータがより明確で使いやすくなります。 ホーム タブを開き、書式設定のドロップダウンメニューから 短い日付を選択します。これにより、抽出されたデータがより明確で使いやすくなります。
A screenshot of formatted dates

注意事項:

  • 元のデータ内のすべての日付エントリが本当に日付形式であり、テキストとして保存されていないことを確認してください。さもないと、数式が期待通りに動作しない可能性があります。
  • データサイズが変更された場合、配列範囲を調整してください。
  • #NUM! または #N/A エラーが表示された場合、空白の入力日付やソースデータの不整合を確認してください。

Kutools for Excelを使用して2つの日付間のすべてのレコードを抽出する

より洗練されたインタラクティブなソリューションを好む場合、Kutools for Excelの「特定のセルを選択」機能を使用すると、数式や手動設定を最小限に抑えながら、日付範囲に一致する全行を抽出することができます。これは、特に複雑なフィルタリングタスクや大規模なデータセットに対するバッチ操作を頻繁に行うユーザーにとって、数式エラーのリスクを軽減し、ワークフローを加速させるのに役立ちます。

Kutools for Excelについて、AI 🤖を搭載し、300以上の便利な機能を提供して作業を簡素化します。

Kutools for Excelをインストール後、次の手順に従ってください。(今すぐKutools for Excelを無料でダウンロード!)

1. まず、分析および抽出したいデータセットの範囲を選択します。次に、 Kutools > Select > Select Specific Cells from the Excel ribbon. This brings up a dialog window for advanced selection.
A screenshot showing Kutools Select Specific Cells feature

2. In the Select Specific Cells dialog:

  • Tick the "Entire row" option to select full matching rows.
  • Set the filter condition: choose Greater than and Less than in the drop-down lists for your date column.
  • Manually enter your start and end dates into the text boxes (make sure format matches your data).
  • Ensure “And” logic is chosen so both conditions apply at once.
See screenshot:
A screenshot of the Select Specific Cells dialog with greater than and less than options

3. Click OK. Kutools will instantly select all rows whose date column falls within your specified range. Then, press Ctrl + C to copy the selected rows, go to a blank sheet or new location, and press Ctrl + V to paste the extracted results.
A screenshot showing extracted rows after using Kutools to select and copy records between two dates

Tips and Cautions:

  • The Kutools approach does not require changing your original data or writing any formulas.
  • If you have date format inconsistencies, preview selection results before copying.
  • Use the feature for repeated or batch filtering jobs—repeating the steps quickly for different date ranges.
  • If your version of Kutools does not show a feature as described, update to the latest version for best compatibility.

Scenario Analysis: This method is ideal for users managing lists with many columns or for those who need to repeatedly extract full records based on changing date limits.


VBA Code - Use a macro to automatically filter and extract all rows between two specified dates

If your workflow often includes extracting data between two dates and you’d like to automate the process entirely, using a VBA macro can be a smart choice. With VBA, you can prompt users to select the date column, enter start and end dates, and automatically filter and copy matched rows to a new sheet. This approach saves manual effort and reduces mistakes, but requires enabling macros and some familiarity with the Visual Basic editor.

Here is how to set up such a macro:

1. Click Developer > Visual Basic to open the VBA editor. In the new Microsoft Visual Basic for Applications window, click Insert > Module, then copy and paste the following code into the Module:

Sub ExtractRowsBetweenDates_Final()
'Updated by Extendoffice
    Dim wsSrc As Worksheet
    Dim wsDest As Worksheet
    Dim rngTable As Range
    Dim colDate As Range
    Dim StartDate As Date
    Dim EndDate As Date
    Dim i As Long
    Dim destRow As Long
    Dim dateColIndex As Long
    Dim cellDate As Variant

    Set wsSrc = ActiveSheet
    Set rngTable = Application.InputBox("Select the data table (including headers):", "KutoolsforExcel", Type:=8)
    If rngTable Is Nothing Then Exit Sub

    Set colDate = Application.InputBox("Select the date column (including header):", "KutoolsforExcel", Type:=8)
    If colDate Is Nothing Then Exit Sub

    On Error GoTo DateError
    StartDate = CDate(Application.InputBox("Enter the start date (yyyy-mm-dd):", "KutoolsforExcel", "", Type:=2))
    EndDate = CDate(Application.InputBox("Enter the end date (yyyy-mm-dd):", "KutoolsforExcel", "", Type:=2))
    On Error GoTo 0

    On Error Resume Next
    Set wsDest = Worksheets("FilteredRecords")
    On Error GoTo 0
    If wsDest Is Nothing Then
        Set wsDest = Worksheets.Add
        wsDest.Name = "FilteredRecords"
        
        rngTable.Rows(1).Copy
        wsDest.Cells(1, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
        wsDest.Cells(1, 1).PasteSpecial Paste:=xlPasteFormats
    End If

    destRow = wsDest.Cells(wsDest.Rows.Count, 1).End(xlUp).Row + 1
    dateColIndex = colDate.Column - rngTable.Columns(1).Column + 1

    For i = 2 To rngTable.Rows.Count
        cellDate = rngTable.Cells(i, dateColIndex).Value
        If IsDate(cellDate) Then
            If cellDate >= StartDate And cellDate <= EndDate Then
                rngTable.Rows(i).Copy
                wsDest.Cells(destRow, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                wsDest.Cells(destRow, 1).PasteSpecial Paste:=xlPasteFormats
                destRow = destRow + 1
            End If
        End If
    Next i

    Application.CutCopyMode = False
    wsDest.Columns.AutoFit
    MsgBox "Filtered results have been added to '" & wsDest.Name & "'.", vbInformation
    Exit Sub

DateError:
    MsgBox "Invalid date format. Please enter dates as yyyy-mm-dd.", vbExclamation
End Sub

2. To run the macro, click the Run button (Run) button or press F5.

Then follow the prompts to finish the steps:

  1. Select the data table (including headers)
    When the first input box appears, select the entire table, including the header row. Click OK.
  2. Select the date column (including header)
    When the second input box appears, select only the date column, including the header. Click OK.
  3. Enter start and end dates
    You’ll be asked to enter the start date (format: yyyy-mm-dd, e.g., 2025-06-01)
    Then enter the end date (e.g., 2025-06-30)
    Click OK after each.

A worksheet named FilteredRecords will be created automatically (if it doesn't already exist). The matching rows (where the date falls between the start and end dates) will be copied to that sheet. And any new matching rows will be appended below existing results each time you run the macro.

Troubleshooting:

  • If nothing happens after running, check your selected ranges—invalid ranges or canceled dialogs will exit the macro.
  • Make sure your date column entries are true Excel dates; if stored as text, convert them first for accurate filtering.

Scenario Analysis: This VBA solution is particularly valuable for repetitive tasks, advanced workflows, or when sharing a semi-automated solution with non-technical users—just assign a button for even easier operation.


Other Built-in Excel Methods - Use Excel's built-in Filter feature

For users who prefer a simple, interactive approach without writing formulas or code, Excel's built-in Filter feature offers a quick way to view and extract rows between two dates. This is ideal for occasional tasks, visual checking, or when you need to work directly with the worksheet interface. However, it doesn't provide automatic updates if your date criteria or data change—you need to repeat the steps for each new filter session.

Here's how to use it:

  • Select your data range, ensuring the column headers are included.
  • Go to the Data tab on the ribbon, then click Filter. Small drop-down arrows will appear next to each header.
  • Click the arrow for your date column and choose Date Filters > Between....
  • In the dialog box, enter your desired start and end dates. Make sure the format matches your data's date format.
  • Click OK. Only the rows with dates in your specified range will remain visible.
  • Select all visible rows, press Ctrl + C to copy, go to a blank area or another sheet, and press Ctrl + V to paste the filtered results.

Tips and Precautions:

  • This method is best for quick and visual inspection or ad-hoc extraction.
  • If your date column uses inconsistent formats, correct these beforehand to ensure the filter works accurately.
  • Remember to clear the filter when you’re done to reveal the full data set again.
  • Filtered rows are hidden, not deleted—your original data remains intact.

Scenario Analysis: Excel's built-in Filter is most suitable for moderate-sized tables and when you need to instantly preview or copy subsets without saving formulas or macros.


Troubleshooting and Summary Suggestions:

  • Always confirm your date cells are formatted consistently across the worksheet for all solutions to work correctly.
  • When using formulas or VBA, adjust column and range references to match the actual structure of your sheet to avoid index or reference errors.
  • For performance on very large datasets, Kutools or built-in filtering typically offer faster results and are less likely to exceed memory/formula calculation limits compared to extensive array formulas.
  • If you encounter unexpected blanks or missing records in the output, double-check that your date conditions, input ranges, and data formats are set as intended.

Demo: Extract all records between two dates by Kutools for Excel

 
Kutools for Excel: あなたの指先に 300 以上の便利なツールが集結!永久無料のAI機能をお楽しみください!今すぐダウンロード!

最高のオフィス生産性ツール

🤖 Kutools AI Aide:データ分析を革新:インテリジェント実行   |  コード生成  |  カスタム数式の作成  |  データを分析してグラフを生成  |  Kutools Functions を呼び出す
人気機能重複の検索・ハイライト・マーキング   |  空白行を削除   |  データを失わず列やセルを統合   |   丸める ...
スーパーLOOKUP複数条件VLOOKUP   複数値VLOOKUP  |  複数シートの検索  |  ファジーマッチ ....
高度なドロップダウンリストすばやくドロップダウンリストを作成   |  依存型ドロップダウンリスト   |  複数選択ドロップダウンリスト ....
列の管理:特定数の列を追加  | 列を移動  | 非表示列の表示状態を切り替え |  範囲と列の比較 ...
注目機能グリッドフォーカス   |  デザインビュー  |  強化された数式バー   ワークブック&ワークシートの管理   |  オートテキスト ライブラリ (Auto Text)   |  日付ピッカー   |  データの統合   |  セルの暗号化/復号化    リスト送信で電子メールを送信   |  スーパーフィルター   |   特殊フィルタ(太字/斜体/取り消し線でフィルタ...)
トップ15ツールセット12 種類のテキストツールテキストの追加特定の文字を削除など)  |  50 種以上のグラフ タイプガントチャートなど)  |  40を超える実用的な 数式誕生日に基づいて年齢を計算する、など)  |  19種の 挿入ツールQRコードの挿入パスから画像の挿入など)  |  12種類の 変換ツール単語に変換する通貨変換など)  |  7つの 結合&分割ツール高度な行のマージセルの分割など)  |  ...さらに多数
お好きな言語でKutoolsを使用できます ― 英語、スペイン語、ドイツ語、フランス語、中国語など40以上に対応!

Kutools for ExcelでExcelスキルを強化し、かつてない効率を体験しましょう。 Kutools for Excelは300以上の高度な機能で生産性向上と時間短縮を実現します。最も必要な機能を今すぐ取得...


Office TabはOfficeにタブ表示を追加し、作業効率を大幅に向上させます

  • Word、Excel、PowerPointでタブ編集とタブ閲覧を有効にします
  • 同じウィンドウ内の新しいタブで複数のドキュメントを開いたり作成したりできます。新しいウィンドウを開く必要はありません。
  • 生産性が50%向上し、1日に何百回ものマウスクリックも削減できます!