Copy in a range

  • Thread starter Thread starter moixerno
  • Start date Start date
M

moixerno

Hello,
I'm trying to do a macro VBA for that:

There is a range in a sheet that I don't know how many rows it has.
I want to copy cells from column D to column C (for example), but only in
the range, becouse there's another data in this D and C columns out of the
range.

Can anybody help me?
Thank you very much.
 
Hi,

I'm not sure I completely understand but I think you mean you have date in
column D then a gap then more data and you only want to copy the first
portion of the data and this may help.

Sub prime()
lastrow = Range("D1").End(xlDown).Row
Set myrange = Range("D1:D" & lastrow)
For Each c In myrange
c.Offset(, -1).Value = c.Value
Next
End Sub

Right click you sheet tab, view code and psate this in.

Mike
 
Thanks Mike. It works very well.

Moixerno

Mike H said:
Hi,

I'm not sure I completely understand but I think you mean you have date in
column D then a gap then more data and you only want to copy the first
portion of the data and this may help.

Sub prime()
lastrow = Range("D1").End(xlDown).Row
Set myrange = Range("D1:D" & lastrow)
For Each c In myrange
c.Offset(, -1).Value = c.Value
Next
End Sub

Right click you sheet tab, view code and psate this in.

Mike
 

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