There are two macros you can use to swap the cells
Credit: Mauricio
Sub swap_values()
doc = ThisComponent
sel = doc.CurrentSelection
If sel(0).ImplementationName = "ScCellObj" Then
c1 = sel(0)
c2 = sel(1)
Else
If sel(0).Columns.Count = 2 Then
c1 = sel(0).getCellByPosition(0,0)
c2 = sel(0).getCellByPosition(1,0)
Else
c1 = sel(0).getCellByPosition(0,0)
c2 = sel(0).getCellByPosition(0,1)
End If
End If
tmp = c1.String
c1.String = c2.String
c2.String = tmp
End Sub
There's another macro I wrote, it uses a different approach.
Credit Navshah
Sub Swap()
Dim selection as Object
selection = ThisComponent.getCurrentSelection()
cell1Address = ThisComponent.createInstance("com.sun.star.table.CellRangeAddressConversion")
cell2Address = ThisComponent.createInstance("com.sun.star.table.CellRangeAddressConversion")
cell1Address.Address = selection(0).getRangeAddress
cell2Address.Address = selection(1).getRangeAddress
cell1 = cell1Address.UserInterfaceRepresentation
cell2 = cell2Address.UserInterfaceRepresentation
REM if the cells are in contagious single range
If selection.supportsService("com.sun.star.sheet.SheetCellRange") Then
arr = Split(cell1, ":")
cell1 = arr(0)
cell2 = arr(1)
End If
REM // Get the cell references to write values
cellA = ThisComponent.Sheets(0).getCellRangebyName(cell1)
cellB = ThisComponent.Sheets(0).getCellRangebyName(cell2)
REM // Store CellA values temporarily in a string variable 't'
Dim t as String
t = cellA.String
cellA.String = cellB.String
cellB.String = t
End Sub
Save any of the above macros and assign a shortcut to it.
The complete post can be found here