例えば「123」というパスワードでシートが保護されているとします。
Public Sub swap()
Dim w, x As Range, y As Range
ActiveSheet.Unprotect \u0026quot;123\u0026quot;
If Selection.Areas.Count \u0026lt;\u0026gt; 2 Then
MsgBox \u0026quot;2ヶ所のセルを選択してください\u0026quot;
Exit Sub
End If
Set x = Selection.Areas(1)
Set y = Selection.Areas(2)
w = x.Formula
x.Formula = y.Formula
y.Formula = w
ActiveSheet.Protect \u0026quot;123\u0026quot;
End Sub