By ガードナー 13年2022月XNUMX日水曜日
投稿: Excel
返信 3
いいね 1
ビュー 5.7K
投票 0
サブジェクト関数を変更して、再選択時に既存の選択を削除し、余分な;を削除しました。 改訂されたコードは次のとおりです。

プライベートサブワークシート_Change(ByValターゲットを範囲として)
'によって更新されました Extendoffice 2019/11/13
'KenGardner2022/07/11により更新
範囲としての薄暗い xRng
Dim xValue1 を文字列として
Dim xValue2 を文字列として
Dim semiColonCnt As Integer
Target.Count> 1の場合、Subを終了します
エラーで次の再開
xRng = Cells.SpecialCells(xlCellTypeAllValidation)を設定します
xRngが何もない場合は、Subを終了します
Application.EnableEvents = False
'Application.Intersect(Target、xRng)でない場合は何もありません
If Application.Intersect(Target、xRng)Then
xValue2 = ターゲット.値
アプリケーション.元に戻す
xValue1 = ターゲット.値
Target.Value = xValue2
If xValue1 <> "" Then
If xValue2 <> "" Then
xValue1=xValue2またはxValue1=xValue2&";"の場合またはxValue1=xValue2& ";" Then'リストにXNUMXつしかない場合は、値を残します
xValue1 = Replace(xValue1、 ";"、 "")
xValue1 = Replace(xValue1、 ";"、 "")
Target.Value = xValue1
ElseIf InStr(1、xValue1、 ";"&xValue2)Then
xValue1 = Replace(xValue1、xValue2、 "")'繰り返し選択すると、リストから既存の値が削除されます
Target.Value = xValue1
ElseIf InStr(1、xValue1、xValue2& ";")Then
xValue1 = Replace(xValue1、xValue2、 "")
Target.Value = xValue1

Target.Value = xValue1& ";"&xValue2
終了する場合
Target.Value = Replace(Target.Value、 ";;"、 ";")
Target.Value = Replace(Target.Value、 ";;"、 ";")
InStr(1、Target.Value、 ";")= 1Then'をチェックします; 最初の文字としてそれを削除します
Target.Value = Replace(Target.Value、 ";"、 ""、1、1)
終了する場合
InStr(1、Target.Value、 ";")=1の場合
Target.Value = Replace(Target.Value、 ";"、 ""、1、1)
終了する場合
セミコロンCnt = 0
i = 1の場合Len(Target.Value)へ
If InStr(i、Target.Value、 ";")Then
semiColonCnt = semiColonCnt + 1
終了する場合
私は次の
semiColonCnt=1の場合'削除; 最後の文字の場合
Target.Value = Replace(Target.Value、 ";"、 "")
Target.Value = Replace(Target.Value、 ";"、 "")
終了する場合
終了する場合
終了する場合
終了する場合
application.enablevents = true
End Subの
こんにちはケンガードナー、

共有していただきありがとうございます。 チュートリアルにVBAコードを追加してもかまいません。 Excelで複数の選択または値を使用してドロップダウンリストを作成する方法?

あなたからの便りを楽しみにしています。

アマンダ
·
1年前
·
1が好き
·
0投票
·
0のコメント
·
こんにちはアマンダ、ぜひどうぞ。 元のコードは ExtendOffice.
乾杯、ケン
·
1年前
·
1が好き
·
0投票
·
0のコメント
·
乾杯ケン
·
1年前
·
1が好き
·
0投票
·
0のコメント
·
投稿全体を見る