Auto fill formula from first row in a column to the last active row in the same column?

robdav

New Member
Joined
Dec 1, 2017
Messages
15
I'm trying to right a macro that will insert a formula into cell G2 then auto fill it down to the last active row in column G.

This is my closest attempt but it fails on the 'Selection.Autofill' can anyone help please?

HTML:
    Range("G2").Select    ActiveCell.FormulaR1C1 = _        "=SUBSTITUTE(LEFT(RC[-1],SEARCH("" "",RC[-1])-1),""."",""/"")+0"    ActiveSheet.Range("G2", ActiveSheet.Range("G2").End(xlDown)).Select    Selection.AutoFill

Many thanks

Robert
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
So, are you wanting to overwrite what currently is in column G?
If not (because column G is blank), how do you determine where the last active row in G resides (if there is no data in column G)?
 
Upvote 0
Hi

The column is a newly inserted column into a sheet that has other data in it. There are 13 other columns all if which have the cells populated to the same last row which obviously changes on a daily basis.

I effectively need the last populated row in the sheet to use in the auto fill for column G.

Does that make sense?

Thanks, Rob
 
Upvote 0
OK, then I will just use column F to find where the last row of data occurs.
We don't actually have to use Autofill. We can apply this formula to the whole range at once, like this:
Code:
    Dim lastRow As Long
    
'   Find last row from column F
    lastRow = Cells(Rows.Count, "F").End(xlUp).Row

'   Populate formula
    Range("G2:G" & lastRow).FormulaR1C1 = "=SUBSTITUTE(LEFT(RC[-1],SEARCH("" "",RC[-1])-1),""."",""/"")+0"
 
Upvote 0
You are welcome!

Because the formula uses relative references (R1C1), we are able to assign the formula to the whole range at once.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,754
Messages
6,186,826
Members
453,377
Latest member
JoyousOne

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