![]() |
VBA text for copy + paste
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! |
VBA text for copy + paste
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 "Makaron" wrote in message ... 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! |
VBA text for copy + paste
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). -- Cheers, Shane Devenshire "Makaron" wrote: 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! |
VBA text for copy + paste
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 |
VBA text for copy + paste
Yep - that's what I was looking for. Thank you!
"Dave O" wrote: 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 |
VBA text for copy + paste
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 "Makaron" wrote in message ... Yep - that's what I was looking for. Thank you! "Dave O" wrote: 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 |
All times are GMT +1. The time now is 03:20 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com