fill selected cell with formula

Greasle

New Member
Joined
Jul 24, 2017
Messages
21
#Newbie
Hi all
I tried to write a sub or a function to populate a selected cell with the formular below:

=SUBSTITUTE(LEFT(CELL("filename"), FIND("]", CELL("filename")) - 1), "[", "")

But i fail. Used examples but no luck.

Beware the formula works only with a saved workbook

anyone?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi

Code:
Sub TestThis()
    ActiveSheet.Range("A1").Formula = "=SUBSTITUTE(LEFT(CELL(""filename""), FIND(""]"", CELL(""filename"")) - 1), ""["", """")"
End Sub
 
Upvote 0
or as a UDF

place this formula in any cell
=FilePath()

place in Standard module
Code:
Function FilePath()
    Application.Volatile
    FilePath = Evaluate("=SUBSTITUTE(LEFT(CELL(""filename""), FIND(""]"", CELL(""filename"")) - 1), ""["", """")")
End Function
 
Upvote 0
Hi

Code:
Sub TestThis()
    ActiveSheet.Range("A1").Formula = "=SUBSTITUTE(LEFT(CELL(""filename""), FIND(""]"", CELL(""filename"")) - 1), ""["", """")"
End Sub

Thank you Yongle,

That set me on the road to make :

ActiveSheet.Range(Selection.Address).Formula = "=SUBSTITUTE(LEFT(CELL(""filename""), FIND(""]"", CELL(""filename"")) - 1), ""["", """")"

works.
 
Upvote 0
or as a UDF

place this formula in any cell
=FilePath()

place in Standard module
Code:
Function FilePath()
    Application.Volatile
    FilePath = Evaluate("=SUBSTITUTE(LEFT(CELL(""filename""), FIND(""]"", CELL(""filename"")) - 1), ""["", """")")
End Function

very happy with the Sub.

but the function results in #NAME ?
 
Upvote 0
:eek: "Beware the formula works only with a saved workbook"

Did you take your own advice?
 
Upvote 0
but the function results in "#NAME?" on the same workbook.
Where did you paste the function?
- It must be in a standard module (not Sheet module, not ThisWorkbook module)
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,746
Members
449,050
Latest member
excelknuckles

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