Explanation

In this example, the goal is to pad a number with zeros. To illustrate how Excel functions can be combined, the number of zeros to use is variable and comes from column C. The formula used to solve this problem combines the TEXT function and the REPT function .

Fixed number

The TEXT function returns a number formatted as text, using the number format provided. The TEXT function can apply number formats of any kind to numbers. It is most often used when you want to maintain number formatting for a number when concatenating that number with other text. For example to use the TEXT function to pad a number 3, 4, and 5 zeros:

=TEXT(17,"000") // returns "017"
=TEXT(17,"0000") // returns "0017"
=TEXT(17,"00000") // returns "00017"

Notice the number format works by adding zeros to the left as needed to reach the total number of zeros supplied.

Variable number

To allow a variable number of zeros based on a number in another cell, we can add the REPT function into the mix. The REPT function simply repeats a text string a given number of times:

=REPT("a",2) // returns "aa"
=REPT("a",3) // returns "aaa"
=REPT("a",4) // returns "aaaa"

So to pad a number with 5 zeros, we can use REPT to assemble the five zeros into the text"00000":

=TEXT(17,REPT("0",5)) // returns "00017"

The formula used in the example shown is simply a variation of the above formula. The formula in E9 evaluates like this:

=TEXT(B9,REPT("0",C9))
=TEXT(29,REPT("0",5))
=TEXT(29,"00000")
="00029"

Other characters

You can adapt this formula to use any character you like:

=TEXT(29,REPT("*",5)) // returns "***29"
=TEXT(29,REPT("-",5)) // returns "---29"

Pad for display only

Padding a number with zeros with the TEXT function changes the number into text, which may not suit your needs. To simply display a number with padding, you can use a regular number format . For example, to pad a number with 5 zeros for display only, select the cells and use the shortcut Control + 1 to open the Format Cells window. Then:


Format cells > Number > Custom > "00000"

With this approach, the number is not converted to text but remains a true number. More details here .

Explanation

The FILTERXML function can parse XML using XPath expressions. XML is a special text format designed to transport data, with features that allow it to be easily parsed and verified by software. XPath is a query language for selecting the elements and attributes in an XML document. The FILTERXML function uses XPath to match and extract data from text in XML format.

In the example shown cell B5 contains XML data that describes 10 music albums. For each album, there is information about the title, the artist, and the year. To parse this XML, the FILTERXML function is used 3 times in cells D5, E5, and F5 are as follows:

=FILTERXML(B5,"//album/title") // get title
=FILTERXML(B5,"//album/artist") // get artist
=FILTERXML(B5,"//album/year") // get year

In each case, the XPath expression targets a specific element in the XML. For example, in cell D5, the XPath targets the title element with this string:

"//album/title"

With this XPath expression, FILTERXML returns all 10 album titles. Because this example has been created in Excel 365 , which supports dynamic arrays , the results spill into the range D5:D14 automatically.