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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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
:warning: "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,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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