From: Sometimes, there are two adjoining cells need to be swapped. We can manually do it easily. Look at the following screenshot, I want to swap cell A4 and B4, please do as follows:.
Select the cell you want to swap. In this example, select cell A4. Press Shift key, and put the cursor at the right border.
![]()
Then drag the cursor to the right border of cell B4. When there displays “工”, release the mouse. And the two cell contents have been swapped.
Oct 19, 2018 - In Numbers, you can move rows and columns and transpose them.
With this method, we can also swap two adjoining rows or columns. By easy, I mean either a keyboard shortcut or menu item, without involving copying to temporary cells or writing VBA scripts or anything like that.
![]()
I'm looking for a way to just select two cells and click some menu item or press some key combination that will swap their contents. Why impose this restriction? Creating a macro makes this trivial. As far as I know, it can't be done any other way.
You can assign the macro to a button or hotkey. Sub Swap If Selection.Count 2 Then MsgBox 'Select 2 cells (only) to swap.'
Exit Sub End If Set trange = Selection If trange.Areas.Count = 2 Then temp = trange.Areas(2) trange.Areas(2) = trange.Areas(1) trange.Areas(1) = temp Else temp = trange(1) trange(1) = trange(2) trange(2) = temp End If End Sub. I read this post but actually needed a macro to swap full ranges. In addition, I needed to swap the colors. Modded the originally posted macro slightly, this might be useful for someone.
Sub Swap If Selection.Areas.Count 2 Then MsgBox 'Select 2 cell ranges (only) to swap.' Exit Sub End If If Selection.Areas(1).Count Selection.Areas(2).Count Then MsgBox 'The two areas must be of equal size' Exit Sub End If 'With this for loop we run through each cell 1 by 1 For i = 1 To Selection.Areas(1).Count 'Swapping values temp = Selection.Areas(1)(i) Selection.Areas(1)(i) = Selection.Areas(2)(i) Selection.Areas(2)(i) = temp 'Swapping color tempColor = Selection.Areas(1)(i).DisplayFormat.Interior.Color Selection.Areas(1)(i).Interior.Color = Selection.Areas(2)(i).DisplayFormat.Interior.Color Selection.Areas(2)(i).Interior.Color = tempColor Next i End Sub.
Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |