Copy down to last row iLastRow

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,090
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,898
Office Version
  1. 365
Platform
  1. Windows
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)
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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
 

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,090
Office Version
  1. 365
Platform
  1. Windows
Thanks, Joe. Looked at it many times, didn't catch that.
 
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,167,533
Messages
5,854,291
Members
431,636
Latest member
shabbas313

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