Moving cells with macro?

  • Thread starter Thread starter George K
  • Start date Start date
G

George K

Is it possible to write a macro that cuts the active cell and the cell next
to it and paste them under the last entry of the two columns to its left?

COLUMN A COL B COL C COL D COL E COL F
this 5 new 2
pen 10
that 10 newer 4
pencil 15
the other 2 newest 10
ruler 8
blah 4 low 20
high 10

In the above example, could you put the cursor on Pencil (E2) and make a
macro to cut both it (E2) and next one (F2), and paste them under "high",
"10". i.e. Under the last entry of the two columns to the left?

Also, could it also sort Columns C and D, by Column C?

Thanks,

George
 
George

one way:

Sub MoveCells()
Dim RangeToMove As Range
Dim NextRow As Long
Application.ScreenUpdating = False
If ActiveCell.Column <> 1 Then Exit Sub
Set RangeToMove = ActiveCell.Resize(1, 2)
NextRow = Range("C" & Rows.Count).End(xlUp).Offset(1, 0).Row
With RangeToMove
.Copy Range("C" & NextRow)
.Delete Shift:=xlShiftUp
End With
Application.ScreenUpdating = True
End Sub

Regards

Trevor
 
something like. UNTESTED

activecell.resize(1,2).cut
cells(rows.count,activecell.offset(,-2).end(xlup).row+1,activecell.offset(,2
))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top