How to use Filldown properly

ExcelPupper

Board Regular
Joined
Mar 2, 2020
Messages
112
Office Version
  1. 2019
Platform
  1. Windows
Hi I just want to confirm what's wrong on the code below particularly in the Filldown portion? It won't run properly when I tried it earlier.
Just to add, I am trying to copy the formula on Sheet1.Range (B2:E2) until the last row with data using column A of Sheet1 as reference.
Thanks!

VBA Code:
Sub CopyData()

Dim lr As Long, lr2 As Long

lr = Sheets(3).Range("B" & Rows.Count).End(xlUp).Row
lr2 = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row


    Sheets(3).Range("B2:B" & lr).Copy
 
  
    Sheets(1).Range("A2").PasteSpecial Paste:=xlPasteValues
    Sheets(1).Range("A:A").RemoveDuplicates Columns:=1, Header:=xlNo
    Sheets(1).Range("B2:E" & lr2).FillDown
      
  

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

ExcelPupper

Board Regular
Joined
Mar 2, 2020
Messages
112
Office Version
  1. 2019
Platform
  1. Windows
In what way?
Hi, on the Filldown portion it only copies the Column Names (Cells B1:E1) then paste it on the Cells B2:E2. And the macro ends without giving any error.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
67,955
Office Version
  1. 365
Platform
  1. Windows
Ok, you are calculating the last row in sheets(1) before you add the data & remove the duplicates. Move that line to just before you fill down.
 
Solution

ExcelPupper

Board Regular
Joined
Mar 2, 2020
Messages
112
Office Version
  1. 2019
Platform
  1. Windows
Ok, you are calculating the last row in sheets(1) before you add the data & remove the duplicates. Move that line to just before you fill down.
Ohh okay, now I get it. Initially it captures the header of column A from Sheet1. Thanks for the tip!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
67,955
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,840
Messages
5,766,729
Members
425,375
Latest member
Bradleyckx

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
Top