VBA function format

Format function with the TEXT worksheet function uses the same basic VBA, but more powerful, many formats can only be used VBA's Format function, and can not be used worksheet function TEXT.

Format (value format (optional))
a digital format:
. 1, Number The General: Common numbers, thousands separator can be used to remove an invalid number and 0.
Such as: the Format ( "1,234,567.80", "Number The General") = "1234567.8"
2, the Currency: currency type, can add thousands separator and currency symbol number, reserved two decimal places.
Such as: the Format (1234567, "the Currency") = "¥ 1,234,567.00"
. 3, Fixed: format with two decimal digits.
Such as: the Format ( "123456", "Fixed") = 123,456.00
. 4, Standard: a standard, i.e., with thousands separator and two decimal numbers.
Such as: the Format ( "123456", "Standard") = 123,456.00
. 5, Percent: percentage with two decimal point.
Such as: the Format ( "123456", "Percent") = 12,345,600.00
. 6, Scientific: scientific notation.
Such as: Format ( "1234567", " Scientific") = 1.
06 + 23E . 7, Yes / No: Yes returns a non-zero value when the number, otherwise No.
"As: Format (-3.14," Yes / No ") =" Yes "
    The Format (0, "Yes / No") = "No"
. 8, True / False: returns True if a non-zero value when the number, otherwise False.
7 is similar to the first point, no example here.
9, On / Off: Back On a non-zero value when the number, otherwise returns Off.
7 is similar to the first point, no example here.
10, "" or omitted: return to the original value, but is removed after the decimal point 0 is invalid.
Such as: the Format ( "0.1030", "") = "103."
11,0: placeholder format, bits make up less than 0:00.
"As: Format (123," 0000 ") =" 0123 "
    the Format $ (12.3," 0.00 ") =" 12.30 "
12 is, #: occupying not complement format, bit 0 is insufficient.
As: Format (123, "####") = 123
13%: conversion percentage to a 100% represents multiplied.
as: the Format (1.23, "0.00%") = 123.00%,
    the Format (1.23, "0.00 %%") = 12300.00 %%
14, \: a forced display characters
such as: the Format $ (12.34, "\ R & lt \ M \ B .00") = "RMB 12.34"
15 ,;



Second, the date and time formats:
a fixed format parameters
General Date: basic types
such as: Format ( "2010-5-1 9: 8 : 5", "General Date") = "2010/5/1 9:08: 05 "
long a date: long date operating system definitions
such as: Format (" 2010-5-1 9: 8 : 5 "," long date ") = 2010 Nian 5 Yue 1 Ri
medium date: date
, such as: Format (" . 9 2010-5-1:. 8:. 5 "," Medium a date ") = 10-05-01
short a date: definition short date operating system
, such as: Format (" 2010-5-1 9: 8 : 5 "," a Date Short ") = 2010-5-1
long Time: time defined by the operating system
, such as: the Format (" 2010-5-1. 9:. 8:. 5 "," long Time ") = 9:08:05
Medium Time: with a 12-hour AM / PM (AM / PM), and without seconds
as: Format ( "2010-5-1 9: 8 : 5", "Medium time") = 09:08 am
Short time: 24 when manufactured by time, without seconds
as: Format ( "2010-5-1 9: 8 : 5", "Short time") = 09:08
2. Custom Format
C: national standard formatted as date and time
, such as: Format ( "2010-5-1 9: 8 : 5", "c") = 2010/5/1 9:08:05
y: Day of (1-366) of the year
, such as: the Format ( "2010-5-1. 9:. 8:. 5", "Y") = 121
YY: two-digit year (00-99)
, such as : Format ( "2010-5-1 9: 8 : 5", "yy") = 10
yyy: the above combination of the y yy
"as used: Format (" 2010-5-1 9: 8 : 5 ", "yyy") = 10121
    the Format ( "2010-5-1. 9:. 8:. 5", "y YY Year day") 121 on day 10 =
yyyy: four-digit year (0100-9999)
, such as: Format ( "2010-5-1. 9:. 8:. 5", "YYYY") = 2010
D: the first day of the month (1-31)
, such as: Format ( "2010-5-1 9: 8 : 5" , "d") =. 1
dd: and d are the same, but less than two complement 0:00 
such as: the Format ( "2010-5-1. 9:. 8:. 5", "dd") = 01
ddd: three English letters the day of the week
, such as: Format ( "2010-5-1 9: 8 : 5 ", "ddd") = "Sat"
dddd: English representation of several weeks
, such as: Format ( "2010-5-1 9: 8 : 5 ""dddd ") =" Saturday "
ddddd: standard date display
such as: the Format (" 2010-5-1. 9:. 8:. 5 "," ddddd ") = 5/1/2010
DDDDDD: Long Date
Such as: Format ( "2010-5-1 9: 8 : 5", "dddddd") = 2010 Nian 5 Yue 1 Ri
w: the first few days of the week (starts Sunday, Sunday is 1)
such as: the Format ( "2010-5-1. 9:. 8:. 5", "W") =. 7
WW: the first few weeks of the year
, such as: Format ( "2010-5-1 9: 8 : 5", "ww" ) = 18 is
m: number of months (when used in time may be a minute table)
, such as: the Format ( "2010-5-1. 9:. 8:. 5", "m") =. 5
mm: when less than 10 months with leading 0 (when the time for, may be expressed as a two-digit number of minutes)
, such as: the Format ( "2010-5-1. 9:. 8:. 5", "mm") = 05
MMM: three indicates the number of months of English letters
such as: Format ( "2010-1-1 9: 8 : 5", "mmm") = "Jan"
number of months English representation: mmmm
as: Format ( "2010-1-1 9 :. 8:. 5 "," the mmmm ") =" January "
Q: the first quarters of the year (1-4)
, such as: Format (" 2010-5-1 9: 8 : 5 "," q ") = 2
AAA: several weeks Chinese represented
as: Format ( "2010-5-1 9: 8 : 5", "aaa ") = Saturday
aaaa: Chinese expressed a few weeks
such as: Format (" 2010-5-1 9: 8 : 5 "," aaaa ") = Saturday
h: number (0-23) hours
, such as: Format (" 2010-5-1 9: 8: 5 ", " h ") = 9
) The PM = A / P: Display the current A or P and AM / PM as, for example no longer here. Description: can be used in conjunction with a variety of formats, such as: the Format ( "2010-5-1 9: 8: 5", "DDDDDD aaaa") = 2010 Nian 5 Yue 1 on Saturday, three text formatting @: matching position into the formatter text, such as:





















In the "abcde" inserted before the text "X", code: Format ( "abcde", " X-@") = Xabcde
behind "abcde" 1st character into the text "X", code: Format ( "abcde" , "@X") = aXbcde
in "abcde" insert text characters followed by two "X", code: Format ( "abcde", " @@ X") = abXcde
inserted after "abcde" 3rd character text "X", code: Format ( "abcde", " @@@ X") = abcXde
when long @ break point than the original text string, just add a space at corresponding positions, such as:
the Format ( "ABC" , " X-@@@@") = "X-  ABC"
the Format ( "ABC", " X-@@@@@") = "X-   ABC"
the Format ( "T", "@@ A @") = "AT "(space space at)
with the mating piece of text may be taken from behind, such as:!
taken" abcde "behind a text character, code: the Format (" abcde "," @ "!
) = e taken "abcde" behind the two character text, code: Format ( "abcde", " ! @@") = de
taken back "abcde". 3 character text code: Format ( "abcde", " ! @@@ ") = cde
taken" abcde "behind the two, and added in front of" XY ", code: the Format (" abcde "," the XY @@ ") = Xyde!
&: Character placeholder, and @ is basically the same, not repeat them here.
<: All characters will be forced to appear in lowercase format.
Such as: the Format $ ( "the I Love by You", "<") = I Love you
>: force all the characters displayed in upper case.
Such as: Format $ ( "I Love You ", ">") = I LOVE YOU

Guess you like

Origin www.cnblogs.com/inocalli/p/11002243.html