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

Excelのドロップダウンリストを使用してセルにコピーアンドペーストしないようにするにはどうすればよいですか?

データ検証ドロップダウンリストのあるセルの場合、別のセルからコンテンツをコピーして貼り付けると、ドロップダウンリストがなくなり、新しい貼り付けコンテンツに置き換えられます。 ドロップダウンリストのあるセルに他のコンテンツをコピーして貼り付けないようにしたい場合は、どうしますか? この記事では、この問題に対処するためのVBAメソッドを取得します。

Excelのドロップダウンリストを使用してセルにコピーアンドペーストしないようにする


Excelのドロップダウンリストを使用してセルにコピーアンドペーストしないようにする

1.コピーアンドペーストを防止するドロップダウンリストセルを含むワークシートを開きます。

2。 押す 他の + F11 キーを同時に開いて Microsoft VisualBasicアプリケーション 窓。

3。 の中に Microsoft VisualBasicアプリケーション ウィンドウで、左側のペインで現在のワークシート名をダブルクリックし、以下のVBAコードをコピーしてコードエディターに貼り付けます。 スクリーンショットを参照してください:

VBAコード:ドロップダウンリストを使用してセルにコピーアンドペーストしないようにする

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20200903
    Dim xValue As String
    Dim xCheck1 As String
    Dim xCheck2 As String
    Dim xRg As Range
    Dim xArrCheck1() As String
    Dim xArrCheck2() As String
    Dim xArrValue()
    Dim xCount, xJ As Integer
    Dim xBol As Boolean
'    If Target.Count > 1 Then
'        Exit Sub
'        End If
    xCount = Target.Count
    ReDim xArrCheck1(1 To xCount)
    ReDim xArrCheck2(1 To xCount)
    ReDim xArrValue(1 To xCount)
    Application.EnableEvents = False
    On Error Resume Next
    xJ = 1
    For Each xRg In Target
        xArrValue(xJ) = xRg.Value
         xArrCheck1(xJ) = xRg.Validation.InCellDropdown
        xJ = xJ + 1
    Next

    Application.Undo

    xJ = 1
    For Each xRg In Target
        xArrCheck2(xJ) = xRg.Validation.InCellDropdown
        xJ = xJ + 1
    Next

    xBol = False
    For xJ = 1 To xCount
        If xArrCheck2(xJ) <> xArrCheck1(xJ) Then
            xBol = True
            Exit For
        End If
    Next

    If xBol Then
       MsgBox "The selected cells containg data validation drop-down lists, no pasting allowed."
    Else
        xJ = 1
        For Each xRg In Target
            xRg.Value = xArrValue(xJ)
            xJ = xJ + 1
        Next

    End If

    Application.EnableEvents = True
End Sub

4。 押す 他の + Q 終了するためのキー Microsoft VisualBasicアプリケーション 窓。

5.ドロップダウンリストのあるセルにコンテンツを貼り付けると、貼り付けが許可されていないことを通知するダイアログボックスがポップアップ表示されます。 スクリーンショットを参照してください:

Note:このVBAは、単一セルの貼り付けでのみ機能します。 複数のセルにコピーして貼り付けると、機能しません。

Excelのチェックボックスを使用してドロップダウンリストを簡単に作成します。

  チェックボックス付きのドロップダウンリスト の有用性 Kutools for Excel 必要に応じて、指定した範囲のチェックボックス、現在のワークシート、現在のワークブック、または開いているすべてのワークブックを含むドロップダウンリストを簡単に作成できます。
今すぐKutoolsfor Excelの全機能を30日間無料でダウンロードしてください!


関連記事:

Excelで複数のチェックボックスを含むドロップダウンリストを作成するにはどうすればよいですか?
多くのExcelユーザーは、一度にリストから複数のアイテムを選択するために、複数のチェックボックスを備えたドロップダウンリストを作成する傾向があります。 実際には、データ検証を使用して複数のチェックボックスを含むリストを作成することはできません。 このチュートリアルでは、Excelで複数のチェックボックスを備えたドロップダウンリストを作成するXNUMXつの方法を紹介します。 このチュートリアルでは、問題を解決する方法を説明します。

Excelで別のブックからドロップダウンリストを作成する
ブック内のワークシート間でデータ検証ドロップダウンリストを作成するのは非常に簡単です。 しかし、データ検証に必要なリストデータが別のブックにある場合は、どうしますか? このチュートリアルでは、Excelの別のブックからドロップファウンリストを作成する方法について詳しく学習します。

Excelで検索可能なドロップダウンリストを作成する
多数の値を持つドロップダウンリストの場合、適切な値を見つけるのは簡単な作業ではありません。 以前、ドロップダウンボックスに最初の文字を入力したときにドロップダウンリストをオートコンプリートする方法を導入しました。 オートコンプリート機能に加えて、ドロップダウンリストを検索可能にして、ドロップダウンリストで適切な値を見つける作業効率を高めることもできます。 ドロップダウンリストを検索可能にするには、このチュートリアルの方法を試してください。

Excelのドロップダウンリストで値を選択すると、他のセルに自動入力されます
セル範囲B8:B14の値に基づいてドロップダウンリストを作成したとします。 ドロップダウンリストで任意の値を選択する場合、セル範囲C8:C14の対応する値が選択したセルに自動的に入力されるようにします。 問題を解決するために、このチュートリアルの方法はあなたに有利になります。

ドロップダウンリストのその他のチュートリアル...

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

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

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

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I works BUT after you put the code you cannot UNDO anything. Not a single step back is allowed.
This comment was minimized by the moderator on the site
No, I did not figure it out. I didn't try to resolve after a while.
This comment was minimized by the moderator on the site
did you manage to resolve the issue of copying and pasting into multiple cells? Thanks in advance!
This comment was minimized by the moderator on the site
Hi Dilip, are you able to fix the issue of allowing data using paste values
This comment was minimized by the moderator on the site
Hi Dilip, are you able to fix the issue of allowing data using paste values..i am also facing the same issue..help me on this please
This comment was minimized by the moderator on the site
Thank you very much !! works fine for me !!! copying into a single cell is restricted. but if i copy a list of cells and paste.., the paste is accepted. let me see if i can tune this up ..thanks anyways
This comment was minimized by the moderator on the site
Jepson, did you manage to resolve the issue of copying and pasting into multiple cells? Thanks in advance!
This comment was minimized by the moderator on the site
Private Sub Worksheet_Change(ByVal Target As Range) Dim xValue As String Dim xCheck1 As String Dim xCheck2 As String If Target.Count > 1 Then Exit Sub End If Application.EnableEvents = False xValue = Target.Value On Error Resume Next xCheck1 = Target.Validation.InCellDropdown On Error GoTo 0 Application.Undo On Error Resume Next xCheck2 = Target.Validation.InCellDropdown On Error GoTo 0 If xCheck1 = xCheck2 Then Target = xValue Else MsgBox "No pasting allowed!" End If Application.EnableEvents = True End Sub This Macro not work when copy from different workbook or worksheet then so please tell me how to avoid these things also
This comment was minimized by the moderator on the site
Hi, above mention vba code is not run.kindly resolve.
This comment was minimized by the moderator on the site
Hi, While I running this macro I got this debug error "Application.Undo". Pls resolve this ASAP
This comment was minimized by the moderator on the site
This works but when I paste value this is allowing data which is not from the drop down list. Any way to restrict any value which is not from the list.
This comment was minimized by the moderator on the site
Hi Dilip, Did you able to resolve the issue, i too having similar issue. I have to allow copy,paste only for drop down values in the data validation cell other i have to restrict. Can you share your solution. Thanks Rao
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations