Help using autofill in VBA to copy a formula to only cells that have data within its same row (in an adjacent column)

Yashkar

New Member
Joined
Jan 4, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

When recording the macro, the recorder set the code to autofill from (b2:B39). This was fine for the sheet i was working on, but this macro is intended to be used on sheets with various lengths of data. so i need the macro to be able to identify the "end" of the data and only copy the data till there.

I got as far as this

Sub Test_2()
'
' Test_2 Macro
'

'
Range("B2").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISBLANK(RC[-1]),"""",IF(RC[-1]=R[-1]C[-1],""ommitted multiple daily submission"",""""))"
Range("B3").Select

Selection.AutoFill Destination:=Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
Range(Selection, Selection.End(xlDown)).Select
End Sub

The line in colour is causing an error "run time error 1004. Autofill method of range class failed"

How do I fix this?

Help will be greatly appreciated
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Okay i solved it by adjusting the formula to use actual cell references and it seems to be working
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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