Saturday, September 3, 2016

How to Store the Formula result into a Variable in Excel VBA

Excel Formula to get the Workbook Path and store into a Variable in VBA
Sub Formula_Variable()
Dim SrcSht As Worksheet

Application.DisplayAlerts = False

    Set SrcSht = ThisWorkbook.Sheets("Src_Sht")

    F1 = Evaluate("=LEFT(CELL(""FileName""),FIND(""["",CELL(""FileName""),1)-1)")
    
    SrcSht.Range("C3").Value = F1

End Sub




Notes :
Here the Formula "=LEFT(CELL(""FileName""),FIND(""["",CELL(""FileName""),1)-1)" will returns the Active workbook path.

The Evaluate() Function returns the formula result.

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. If you wish, please share your genuine Feedback or comments only related to this Blog Posts. It is my humble request that, please do not post any Spam comments or Advertising kind of comments, which will be Ignored.