Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

VBA code to copy and paste a cell

I m looking for a VBA code that woud allow me to copy the selected cell in column A and move it a cell in clumn b that is 11 rows up and 2 columns to the right.
0
babychango
Asked:
babychango
1 Solution
 
Shanan212Commented:
Sub Sample()

    Dim Cop
    
    Cop = ActiveCell.Value
    
    Cells(ActiveCell.Row - 11, ActiveCell.Column + 2).Value = Cop
End Sub

Open in new window

0
 
tomHamillCommented:
>>  I m looking for a VBA code that woud allow me to copy the selected cell in column A and move it a cell in clumn b that is 11 rows up and 2 columns to the right.

Not to be too picky or anything, but column B will never be "2 columns to the right" of column A.  It will always be 1 column to the right.  ;-)

Shanon's code will (of course) only work if the active cell is in row 12 or higher.  You may want to add some error handling or check the address of the current cell before running the copy and paste.

Sub Sample()

    Dim Cop
    
    Cop = ActiveCell.Value
    i = ActiveCell.Row
    If i >= 12 Then
         Cells(ActiveCell.Row - 11, ActiveCell.Column + 2).Value = Cop
    End If
End Sub

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now