Copy of last cell until last cell in another column

Kruk07

New Member
Joined
Mar 6, 2015
Messages
19
Hi

I'm working on macro that allow me to copy last cell in column A to all empty rows after that cell in column A until last used raw in column C.

I have tried few but non of them are working.

I have userform that fills the sheet with data but one listbox is multiple selection and in column C I have more lines of entries than in other columns so the gaps needs to be populated with the data in the last row used in column A

Code:
    Dim lastRow As Long
    lastRow = Range("C" & Rows.Count).End(xlUp).Row
    Range("A2").AutoFill Destination:=Range("A2:A" & lastRow)



Thanks

Tom
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How about
Code:
   Range(Range("A" & Rows.Count).End(xlUp), Range("C" & Rows.Count).End(xlUp).Offset(, -2)).Filldown
 
Upvote 0
Thanks

This works great. However when I have only one selection in listbox macro is copy the line one before the last one. Any fix for this?

Thanks
 
Upvote 0
How about
Code:
   Dim LrA As Long, LrC As Long
   LrA = Range("A" & Rows.Count).End(xlUp).Row
   LrC = Range("C" & Rows.Count).End(xlUp).Row
   If LrC > LrA Then Range("A" & LrA & ":A" & LrC).Filldown
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
How about
Code:
   Dim LrA As Long, LrC As Long
   LrA = Range("A" & Rows.Count).End(xlUp).Row
   LrC = Range("C" & Rows.Count).End(xlUp).Row
   If LrC > LrA Then Range("A" & LrA & ":A" & LrC).Filldown
I am obviously missing something, but I do not see where this code produces any different result than your original one-liner in Message #2 did. Why was it necessary to make this change?
 
Upvote 0
If the A5 is the last cell in col A & C5 the last in col C, then the original code will fill A4 into A5
 
Upvote 0
If the A5 is the last cell in col A & C5 the last in col C, then the original code will fill A4 into A5

Ah, I see (I had used a bad set of data values when I tested your code :oops:). Here is another way to write the code...
Code:
With Range(Cells(Rows.Count, "A").End(xlUp), Cells(Rows.Count, "C").End(xlUp).Offset(, -2))
  .Value = .Cells(1).Value
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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