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

Excelで2つのリストボックス間でアイテムを迅速に移動するにはどうすればよいですか?

Author: Sun Last Modified: 2025-05-23

以下のスクリーンショットに示すように、必要に応じてあるリストボックスから別のリストボックスにアイテムを移動しようとしたことはありますか? ここで、Excelでのこの操作について説明します。

a screenshot showing the listboxes before moving items a screenshot of an arrow a screenshot showing the listboxes after moving items

リストボックス間でアイテムを移動


リストボックス間でアイテムを移動

この作業を完了するのに役立つ組み込み関数はありませんが、VBAコードがあります。

1. まず、 Admin_Listsという名前の新しいシートに、リストボックス内のアイテムとして表示されるデータリストを作成する必要があります。

a screenshot of the source data

2. 次に、これらのデータを選択し、名前ボックスに移動して、それらに ItemListという名前を付けます。 スクリーンショットをご覧ください:

a screenshot of naming the source data in the Name box

3. 次に、2つのリストボックスを含むシートで、開発 > 挿入 > リストボックス(Active X コントロール)をクリックし、2つのリストボックスを描画します。 スクリーンショットをご覧ください:

a screenshot of selecting the List Box control under the Developer tab a screenshot of the right arrow a screenshot showing two created list boxes

開発タブがリボンに非表示になっている場合、Excel 2007/2010/2013リボンで開発タブを表示/表示するにはどうすればよいですか? この記事では、それを表示する方法を説明します。

4. 次に、開発 > 挿入 > コマンドボタン(Active X コントロール)をクリックし、2つのリストボックスの間に4つのボタンを描画します。 スクリーンショットをご覧ください:

a screenshot of selecting command button control a screenshot of a right arrow 1 a screenshot showing the created command buttons

ここで、4つのコマンドボタンを新しい名前で名前変更します。

5. 最初のコマンドボタンを選択し、プロパティをクリックし、プロパティウィンドウで BTN_moveAllRightという名前を付け、キャプションの横にあるテキストボックスに>>と入力します。 スクリーンショットをご覧ください:

a screenshot showing how to changing the properties of the command button

6. ステップ5を繰り返して、最後の3つのコマンドボタンに以下の名前を付け、キャプションに異なる矢印を入力します。 スクリーンショットをご覧ください:

BTN_MoveSelectedRight

BTN_moveAllLeft

BTN_MoveSelectedLeft

a screenshot of the second command button after changing the properties a screenshot of the third command button after changing the properties a screenshot of the fourth command button after changing the properties

7. リストボックスとコマンドボタンを含むシート名を右クリックし、コンテキストメニューからコードの表示を選択します。 スクリーンショットをご覧ください:

a screenshot of opening the VBA code editor

8. 下記のマクロコードをモジュールスクリプトにコピーして貼り付け、コードを保存してMicrosoft Visual Basic for Applicationsウィンドウを閉じます。 スクリーンショットをご覧ください:

VBA: 2つのリストボックス間でアイテムを移動

Private Sub Worksheet_Activate()
'UpdatebyExtendoffice20171117
    Dim xCell As Range
    Dim xRg As Range
    Set xRg = Sheets("Admin_Lists").Range("ItemList")
    Me.ListBox1.Clear
    Me.ListBox2.Clear
    With Me.ListBox1
        .LinkedCell = ""
        .ListFillRange = ""
        For Each xCell In xRg
            If xCell <> "" Then
                .AddItem xCell.Value
            End If
        Next xCell
    End With
    Me.ListBox1.MultiSelect = fmMultiSelectMulti
    Me.ListBox2.MultiSelect = fmMultiSelectMulti
End Sub

Private Sub BTN_MoveSelectedLeft_Click()
    Call moveSigle(Me.ListBox2, Me.ListBox1)
End Sub

Private Sub BTN_MoveSelectedRight_Click()
    Call moveSigle(Me.ListBox1, Me.ListBox2)
End Sub

Private Sub BTN_moveAllLeft_Click()
    Call moveAll(Me.ListBox2, Me.ListBox1)
End Sub

Private Sub BTN_moveAllRight_Click()
    Call moveAll(Me.ListBox1, Me.ListBox2)
End Sub

Sub moveAll(xListBox1 As Object, xListBox2 As Object)
    Dim I As Long
    For I = 0 To xListBox1.ListCount - 1
        xListBox2.AddItem xListBox1.List(I)
    Next I
    xListBox1.Clear
End Sub

Sub moveSigle(xListBox1 As Object, xListBox2 As Object)
    Dim I As Long
    For I = 0 To xListBox1.ListCount - 1
        If I = xListBox1.ListCount Then Exit Sub
        If xListBox1.Selected(I) = True Then
            xListBox2.AddItem xListBox1.List(I)
            xListBox1.RemoveItem I
            I = I - 1
        End If
    Next
End Sub

a screenshot showing how to use the VBA code

9. 別のシートに移動してから、リストボックスを含むシートに戻ります。これで、リストデータが最初のリストボックスに表示されているのがわかります。 コマンドボタンをクリックして、2つのリストボックス間でアイテムを移動します。

a screenshot showing the source data in one list box after running the VBA code

選択範囲を移動

a screenshot of moving items from one list box to another one by one a screenshot of the arrow a screenshot showing two items have been moved to the right list box

すべて移動

a screenshot of marking which command button can be used to move all items from one list to another at the same time a screenshot of arrow 2 a screenshot showing all items are moved from one list box to another at the same time

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

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

Kutools for ExcelでExcelスキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、300以上の高度な機能を提供し、生産性を向上させ、保存時間を節約します。  最も必要な機能を入手するにはここをクリック...


Office TabはOfficeにタブインターフェイスをもたらし、作業を非常に簡単にします

  • Word、Excel、PowerPoint、Publisher、Access、Visio、Projectでタブ付きの編集と読み取りを有効にします。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を50%向上させ、毎日数百回のマウスクリックを減らします!