엑셀/vba
두셀의 값을 바꾸기 chatgpt
do121
2023. 2. 23. 20:17
Sub SwapSelectedCells()
Dim tempValue As Variant
Dim cellA As Range, cellB As Range
'Check if exactly two cells are selected
If Selection.Count <> 2 Then
MsgBox "Please select exactly two cells to swap.", vbInformation, "Selection Error"
Exit Sub
End If
'Assign the selected cells to their respective variables
Set cellA = Selection(1)
Set cellB = Selection(2)
'Store the value of cellA in a temporary variable
tempValue = cellA.Value
'Assign the value of cellB to cellA
cellA.Value = cellB.Value
'Assign the value of the temporary variable to cellB
cellB.Value = tempValue
End Sub