Copy down to last row iLastRow

gheyman

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

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,968
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
1,814
Office Version
  1. 365
Platform
  1. Windows
Thanks, Joe. Looked at it many times, didn't catch that.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,110
Messages
5,599,773
Members
414,336
Latest member
Nicolas2465

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