Copy down to last row iLastRow

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
This code is causing me a problem and not sure why. I want to copy the formula in O2 down to the last row
Code:
Sub Add_EOMONTH()
'
    Range("O2").Select
    ActiveCell.FormulaR1C1 = "=EOMONTH(RC[-2],0)"
'
    Dim i As Long
    Dim iLastRow As Long
'
'
        With Sheets("Potential Awards")
            iLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Range("O2").AutoFill Destination:=.Range("O3:O" & iLastRow)
    End With

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
When doing AutoFill, include the cell you are copying as the first cell in your destination range.

So change this:
Code:
.Range("O2").AutoFill Destination:=.Range("O[COLOR=#ff0000][B]3[/B][/COLOR]:O" & iLastRow)
to this:
Code:
.Range("O2").AutoFill Destination:=.Range("O[COLOR=#ff0000][B]2[/B][/COLOR]:O" & iLastRow)
 
Upvote 0
I would also suggest instead of putting the formula in one cell then filling down
You can put the formula in all cells in one stroke.

Code:
Sub Add_EOMONTH()
Dim iLastRow As Long
'
'
With Sheets("Potential Awards")
    iLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Range("O2:O & iLastRow").FormulaR1C1 = "=EOMONTH(RC[-2],0)"
End With
End Sub
 
Upvote 0
Thanks, Joe. Looked at it many times, didn't catch that.
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,706
Members
449,118
Latest member
MichealRed

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