Filling Formulas to the last row in VBA

Setofskills

New Member
Joined
Aug 17, 2015
Messages
9
I'm a bit out of my element here and have written a script that will bring in some new project numbers and it puts those on the bottom of Column B. Column A contains formulas (Column A is an error check), Column B is the list of project numbers, Column C through AC are formulas based off of the project number in column B. I can't figure out how to fill the data to the last row of data. Here is what I've attempted to do, I've done my best to explain what I think it is I'm doing (note, data headers are in row 1 and 2, data begins in row 3):

Sub Add_Projects_to_List()
' Add new projects to Projects tab

Dim LastRow As Long

Sheets("Monthly Data").Select
' Selecting the Data Tab

ActiveSheet.Range("$A$1:$CV$2000").AutoFilter Field:=100, Criteria1:="<>"
Range("A2:A2000").SpecialCells(xlCellTypeVisible).Copy
' Bringing in the new project numbers that are filtered out on the data page. I imagine my range here is overkill, but I also didn't know how to select the range through the last row... not pretty, but it seems to work.

Sheets("Projects").Select
' Trying to put these projects on the Projects tab.
Range("B2").Select
Selection.End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
' Pasting the Data

Sheets("Monthly Data").ShowAllData
' Clearing the filter

LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Range("C3:AC" & LastRow).FillDown
Range("A3:A" & LastRow).FillDown
' This does not work, but it is my attempt to fill all the formulas down to what is the new last row for columns A and C through AC.

Range("A1").Select

End Sub

Any help or advice as to why this doesn't work will be greatly appreciated!!!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You must have a value in the first cell of the range you want to fill down. That cell must be included in the fill range. eg. If your data to be filled down is in row 2, then row 2 would need to be part of the fill range,
Code:
Range("A2:AC" & LastRow).FillDown
If the first cell containing the data to be filled is not included in the fill range, the statement is ignored by the compiler. The code above is an example and I notticed that you skipped column B.
 
Upvote 0
You must have a value in the first cell of the range you want to fill down. That cell must be included in the fill range. eg. If your data to be filled down is in row 2, then row 2 would need to be part of the fill range,
Code:
Range("A2:AC" & LastRow).FillDown
If the first cell containing the data to be filled is not included in the fill range, the statement is ignored by the compiler. The code above is an example and I notticed that you skipped column B.

My headers are in both rows 1 and 2, so my formulas start in row 3 and row 3 does contain formulas, so I'm missing something else here, any other ideas!?
 
Upvote 0
the only other thing I can think of is that your LastRow variable might be returning a value less <=3.
 
Last edited:
Upvote 0
Try making this change
Code:
LastRow = Cells(Rows.Count, [COLOR=#ff0000]2[/COLOR]).End(xlUp).Row
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,495
Messages
6,125,149
Members
449,208
Latest member
emmac

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