엑셀/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

'엑셀 > vba' 카테고리의 다른 글

잔액 구하기 chatgpt  (0) 2023.04.06
userform 팝업메뉴 2 chatgpt  (0) 2023.03.17
userform 팝업메뉴 만들기  (0) 2023.02.24
시트 이동 chatgpt  (0) 2023.02.23
통합문서 합치기 chatgpt  (0) 2023.02.22