vba code for copy last cell in column A to the range from cell below in column A to the last row in column B

linghu

New Member
Joined
Aug 17, 2015
Messages
1
Hi Guys
I can't figure out how to get this code right:
Basically I want a code to identify last row in column A, copy that cell to from the cell below to the cell in last row in the data sheet. So with the simple example:
I want to copy 2/8/2015 to the two empty cell below, which has the same row numbers as column B.
Everything else worked apart from the last paste to the desired range I want.
What I had was:
Range("A" & LastRow + 1, ["A" & Cells(Rows.Count, "B").End(xlUp).Row]).PasteSpecial
This doesn't work either:
Range("A"& LastRow + 1: "A" & Cells(Row.Count, "B").End(xlUp).Row).PasteSpecial

LastRow has already been defined as the last row of column A

[TABLE="width: 500"]
<tbody>[TR]
[TD]
Date
[/TD]
[TD]Product[/TD]
[/TR]
[TR]
[TD]1/8/2015[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]2/8/2015[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]D[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Welcome to the board, try:
Code:
Dim LR_A as Long
Dim LR_B as Long

LR_A = Range("A" & Rows.Count).End(xlUp).row
LR_B = Range("B" & Rows.Count).End(xlUp).row

If LR_B > LR_A Then
    Range("A" & LR_A).Resize(LR_B - LR_A + 1).Value = Range("A" & LR_A).Value
End If
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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