VBA Autofill formula

ksr329

New Member
Joined
Nov 14, 2012
Messages
3
Hi I am trying to write a code that will autofill the formula in cell B7 down to the last row in column A. This macro is run on multiple worksheets where the number of rows will change. The problem I am having is when a worksheet only has one row of data and therefore does not need the autofill feature. Is there a way I can tell the macro to autofill the formula if there is data below row 7 and if not to just enter the formula?

So far I have:

Range("B7").Select
ActiveCell.FormulaR1C1 = "=TRIM(MID(R4C3,5,8))"
Selection.AutoFill Destination:=Range("B7:B" & LRow)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Maybe...

Code:
Sub filldown()
    Dim LRow As Long
    LRow = Range("A" & Rows.Count).End(xlUp).Row
    If LRow < 7 Then Exit Sub
    Range("B7:B" & LRow).FormulaR1C1 = "=TRIM(MID(R4C3,5,8))"
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,025
Messages
6,128,336
Members
449,443
Latest member
Chrissy_M

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