VBA text for copy + paste

  • Thread starter Thread starter Makaron
  • Start date Start date
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!
 
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
 
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).
 
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
 
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
 

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