ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Copy and Paste (https://www.excelbanter.com/excel-discussion-misc-queries/177788-copy-paste.html)

jase

Copy and Paste
 
I am trying create a macro at the push of a button to copy data from a
certain cell or range of cells and then paste into another cell, however if
that cell I am pasting into has data in it I want it to go down 3 cells and
paste it, and so on and so on. I would imagine using the loop function would
work for me but I can't seem to figure it out.


Dave Peterson

Copy and Paste
 
Dim RngToCopy as range
Dim DestCell as range

with worksheets("Sheet999")
set rngtocopy = .range("a1") 'whatever you want
end with

with worksheets("sheet888")
set destcell = .range("x99") 'some starting cell
end with

do
if isempty(destcell.value) then
exit do
else
set destcell = destcell.offset(3,0)
end if
loop

rngtocopy.copy _
destination:=destcell


Jase wrote:

I am trying create a macro at the push of a button to copy data from a
certain cell or range of cells and then paste into another cell, however if
that cell I am pasting into has data in it I want it to go down 3 cells and
paste it, and so on and so on. I would imagine using the loop function would
work for me but I can't seem to figure it out.


--

Dave Peterson

jase

Copy and Paste
 
Dave, thank you for the help but the data is just pasting over the DestCell
its not looking for the next available free cell.

"Dave Peterson" wrote:

Dim RngToCopy as range
Dim DestCell as range

with worksheets("Sheet999")
set rngtocopy = .range("a1") 'whatever you want
end with

with worksheets("sheet888")
set destcell = .range("x99") 'some starting cell
end with

do
if isempty(destcell.value) then
exit do
else
set destcell = destcell.offset(3,0)
end if
loop

rngtocopy.copy _
destination:=destcell


Jase wrote:

I am trying create a macro at the push of a button to copy data from a
certain cell or range of cells and then paste into another cell, however if
that cell I am pasting into has data in it I want it to go down 3 cells and
paste it, and so on and so on. I would imagine using the loop function would
work for me but I can't seem to figure it out.


--

Dave Peterson


jase

Copy and Paste
 
Never mind I got it to work. Thanks Dave.


"Jase" wrote:

I am trying create a macro at the push of a button to copy data from a
certain cell or range of cells and then paste into another cell, however if
that cell I am pasting into has data in it I want it to go down 3 cells and
paste it, and so on and so on. I would imagine using the loop function would
work for me but I can't seem to figure it out.



All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com