Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a worksheet of start times where it is sometimes necessary to swap a
rage of 4 cells with another...say A4:D4 with A9:D9. I've found a macro which swaps only 2 cells.... say A25 with A3 but I don't know if it could be modified. All I can think of is a macro which would say copy A4:D4 to empty cells....J4:M4 (after selecting A4) then I Select A9 which would copy A9:D9 to J9:M9. After this the macro would go J64000 endX1 up cut J9:M9.....A1 end down , offset (1,0) Paste ....same for J4:M4. Looks inelegant and I'd have to work out how to select a cell in the middle of a macro. Any ideas if this macro could be modified? Sub SwapSelections() Dim rCell1 As Range Dim rCell2 As Range Dim strg1 As String, strg2 As String If Selection.Cells.Count 2 Or Selection.Cells.Count < 2 Then MsgBox "Your selection should only contain 2 cells", vbCritical End End If If Selection.Areas.Count 1 Then Set rCell1 = Selection.Areas(1).Cells(1, 1) Set rCell2 = Selection.Areas(2).Cells(1, 1) ElseIf Selection.Rows.Count Selection.Columns.Count Then Set rCell1 = Selection.Range("A1") Set rCell2 = Selection.Range("A2") Else Set rCell1 = Selection.Range("A1") Set rCell2 = Selection.Range("B1") End If strg1 = rCell1 strg2 = rCell2 rCell1 = strg2 rCell2 = strg1 End Sub Regards Dennis |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
swap | Excel Worksheet Functions | |||
I need to swap last name, first name in a cell to first name last | Excel Worksheet Functions | |||
Swap the X and Y axes | Charts and Charting in Excel | |||
Swap Cells | Excel Discussion (Misc queries) | |||
Last, First Name Swap | Excel Programming |