VBA autofil formula in Collumn D if data is inputted into column B

ljkennedy

New Member
Joined
Sep 12, 2019
Messages
4
Hi all,
I am in need of a VBA code to be able to autofill this formula "=IF(ISNUMBER(--MID($B:$B,SEARCH("241",$B:$B),3)),MID($B:$B,18,10),0)" into column D anytime datat is inputted, this is an attempt to limit the amount of formula's are in the sheet as i dont want to have to copy the formula each time or have a long amount of cells with formula that arent needed, i tried this formula that i found on another thread but it doesnt work
Sub Ratio_BC()
Dim Lastrow As Long

Application.ScreenUpdating = False

Lastrow = Range("B" & Rows.Count).End(xlUp).Row
Range("D2").Formula = "=IF(ISNUMBER(--MID($B,SEARCH("241",$B),3)),MID($B,18,10),0)"
Range("D2").AutoFill Destination:=Range("D2:D" & Lastrow)
ActiveSheet.AutoFilterMode = False

Application.ScreenUpdating = True

End Sub
any help would be appreciated
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello LjKennedy,

Try the code amended as follows:-


Code:
Sub Ratio_BC()

Dim Lastrow As Long

Application.ScreenUpdating = False

Lastrow = Range("B" & Rows.Count).End(xlUp).Row
Range("D2:D" & Lastrow).Formula = "=IF(ISNUMBER(--MID($B,SEARCH(""241"",$B),3)),MID($B,18,10),0)"

Application.ScreenUpdating = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Hi vcoolio,
Thanks for replying,
I tried running that code but it comes up with "run time error '1004' application defined or object defined error
 
Upvote 0
You're welcome Ljk. I'm glad to have been able to assist.

For the sake of anyone else who may come by this way looking for a similar solution, could you please post what the 'fix' was.
Thanks Ljk.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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