Many times we encounter with such a situation when we have a “String” and from this string we need to fetch a value in fromat of Date, Percentage, Currency, Fixed, Scientific, Yes/No, On/Off etc.

Here comes the most used function of VBA, The “Format() Function”.

**Syntax:**

**Format(Expression,[Format])**

*Expression* is the String which you pass in order to fetch the desired output. *Format *is the optional argument. If you don’t pass *Format* then you will get the same String which you passed as input.

Although, Excel has it’s own formats for the data but You can define your own [Format] too. Here is the list of the Defined Formats in the Excel 2007:

```
General Number -This gives you the same string as you passed as input
Fixed -Atleast one digit on the left and two digits after the decimal place
Currency -With Thousand Separators along with 2 decimal places
Standard -Thousand separator, atleast one digit at the left of decimal place and two digit at
the right the decimal place
Percent -Displays the percent value with two digits at the right of decimal place
True/False -True for zero and False for Non-Zero
On/Off -OFF for Zero and On for non Zero
Yes/No -Displays No for zero and Yes for non-zero
```

**Examples:**

```
Format("1234","General Number") 'returns 1234
Format("1234","currency") 'returns $1,234.00
Format("1234","Fixed") 'returns 1234.00
Format("1234","Standard") 'returns 1,234.00
Format("1234","Percent") 'returns 123400.00%
Format("1234","Yes/No") 'returns Yes
Format("1234","General Date") 'returns 5/18/1903
Format("1234","Long Date") 'returns Monday, May 18, 1903
Format("1234","MMM, DDDD YYYY") 'returns May, Monday 1903
```

### Like this:

Like Loading...