How to Get File Name in Excel (Formula)

- Written by Puneet

In Excel, there is no direct function to get the name of the file, but you can use the CELL function to get the path of the file, and then we can use the MID function to extract the file name from it.

You can use the following steps:

  1. First, you need to enter the CELL function in a cell.
  2. After that, you need to specify the “filename” in the argument.
  3. Next, enter the closing parentheses
  4. In the end, hit enter.
=CELL("filename")

At this point, you have the address path of the file. You can see in the following example that I have the path address in cell D1.

get-file-name

Now the next thing is to get the name of the file from this address, and for this, we will use the MID + SEARCH functions.

There’s one thing that you need to note down the name of the file is in the square brackets. So, let’s create a formula to get the name of the file.

  1. First, use the SEARCH function to know the position of the starting square bracket by using the search function.
    search-function-to-know-the-position
  2. Next, you need to find the position of the ending square brackets.
    position-of-ending-square-brackets
  3. After that, you need to use the MID function to get the fine name from the entire path.
  4. And for this, we need to use the following formula where you need to use the values that you have got from the search function.
    mid-function-to-get-file-name

Now let’s understand this formula that we have written with the MID function. In the MID function:

  1. In the first argument, you have referred to the cell where we have the full path of the file.
  2. In the second argument, you have used the position of starting square bracket which you have got from the SEARCH function and then added 1 into it.
  3. In the third argument, you used the position of the ending square bracket and deducted the position of the starting square bracket, and after that deducted 1 from it. This gives you the exact number of characters to get.

Here I have input all the functions in a single formula to get the result in a single cell.

=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

Get the Excel File

Leave a Comment