VBA text for copy + paste

M

Makaron

I'm trying to copy a cell from directly above of a particular cell and insert
it into the given cell, as part of a macro. What commands would that consist
of in VBA?

Thank you very much!
 
R

Rick Rothstein \(MVP - VB\)

Assuming you are asking because the cell you want to fill in is variable,
see if this does what you want...

CellAddress = "S9"
......
......
Range(CellAddress).Value = Range(CellAddress).Offset(-1, 0).Value

Rick
 
S

ShaneDevenshire

Hi,

Move to the cell where you want to start from (the one below the one you
want to copy). Turn on the macro recorder and record the code. (Tools,
Macro, Record New Macro).
 
D

Dave O

One way: This code copies the cell directly above the current cell,
returns to the current cell and pastes:

activecell.offset(-1,0).select
selection.copy
activecell.offset(1,0).select
activesheet.paste

Dave O
Eschew obfuscation
 
R

Rick Rothstein \(MVP - VB\)

Just as a follow up, you don't need to actually select the cell to copy it.
This code will do the identical thing that Dave O's code does...

ActiveCell.Offset(-1, 0).Copy ActiveCell

or, if you like the self documenting nature of named arguments, like this...

ActiveCell.Offset(-1, 0).Copy Destination:=ActiveCell

Rick
 
Top