VBA - How do you paste until the end of the rows in the next column?

ynchoir

New Member
Joined
Jul 1, 2012
Messages
5
Hi everyone,

I am a beginner in Excel VBA and got stuck in a part of my code.
What I want to do is to transform the data from
[Before Macro]
title
xxx
xxx
xxx
xxx

[After Macro]
title
title xxx
title xxx
title xxx
title xxx



<tbody>
</tbody>
In words, I just want to copy the element in the first row to the first column, until the end of the data xxx.

The length of the data xxx varies, depending on the context.

My code so far is

Selection.Copy
ActiveCell.Offset(1, -1).Range("A1:A100").Select
ActiveSheet.Paste


But I want to adjust the range to paste to "the end of the rows in the next column", not "A100".

What should I do? Any helps will be much appreciated!

yn
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi,
let Your Data be in Columns A:B, try using the macro of the form:
Code:
Sub aaa()
Dim a&

a = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:A" & a).Copy Range("B2")
Range("A2:A" & a).Value = Cells(1, 1).Value
End Sub
Best regards.
 
Upvote 0
Thank you very much for your suggestion.
I guess I wanted to copy the data in the location of the cursor (at the time of macro execution), not necessarily the data in "A1" cell.
Also, I did not want to delete the data right below the title. I mean, I should have written

[Before]
empty title
empty xxx
empty xxx

[After]
empty title
title xxx
title xxx

Does it have to do with 'Offset' function?
Thank you for your suggestion though. I would be happy to hear from you.
yn


Hi,
let Your Data be in Columns A:B, try using the macro of the form:
Code:
Sub aaa()
Dim a&

a = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:A" & a).Copy Range("B2")
Range("A2:A" & a).Value = Cells(1, 1).Value
End Sub
Best regards.
 
Upvote 0
Try this code:
Code:
Sub bbb()
Dim b&

b = Cells(Rows.Count, 2).End(xlUp).Row
Cells(2, 1).Resize(b - 1) = Selection.Value
End Sub
Best regards.
 
Upvote 0
Thank you very much. It still copies everything in Column A, not the next column (i.e. one step left from the original cursor.), though.
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top