Vba Macro Formula copied to a cell by range

lapot

New Member
Joined
Jul 25, 2014
Messages
30
Dear all
I am try to insert this formula "=MID(E2,FIND(""Bill ref"",E2,1) + 8, 7) & MID(E3, LEN(E2)-0,0)" with below code into B2 which runs as long as the data range on Column E


When the formula entered it becomes "=MID('E2',FIND("Bill ref",'E2',1) + 8, 7) & MID('E3', LEN('E2')-0,0)" and gives #NAME? error this is because cell names get ‘’ added as in ‘E2’ , when I cleared them then formula works. Do you know why this happens also formula cell reference doesn’t change as it was copied down. Can this be turn into variable For example E2,E3,E4,E5….. etc


Code:
Sub CopyFormula()
Dim lngLastRow As Long 'declare a variable for the last row
lngLastRow = Range("E" & Rows.Count).End(xlUp).Row
Range("B2:B" & lngLastRow).FormulaR1C1 = "=MID(E2,FIND(""Bill ref"",E2,1) + 8, 7) & MID(E3, LEN(E2)-0,0)"
End Sub

kind regards

 

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.
Try

Rich (BB code):
Range("B2:B" & lngLastRow).Formula = "=MID(E2,FIND(""Bill ref"",E2,1) + 8, 7) & MID(E3, LEN(E2)-0,0)"
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,435
Members
448,898
Latest member
dukenia71

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