{"id":353,"date":"2013-02-28T10:19:20","date_gmt":"2013-02-28T10:19:20","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=353"},"modified":"2020-04-23T11:02:36","modified_gmt":"2020-04-23T11:02:36","slug":"excel-vba-lesson-9","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-9\/","title":{"rendered":"Excel VBA Lesson 9: Formatting Functions"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-8-string-functions\/\">&lt;&lt;Lesson 8&gt;&gt;<\/a><a href=\"http:\/\/excelvbatutor.com\/index.php\/tutorial\/\"> [Contents]<\/a> <a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-10-financial-functions\/\">&lt;&lt;Lesson 10&gt;&gt;<\/a><\/strong><\/h4>\n\n\n\n<p>We need to format the output of an Excel VBA code so the users can understand it easily. In the previous lesson, we have learned a few basic formatting functions like&nbsp;<strong>Int, Fix<\/strong> and <strong>Round<\/strong>. However,&nbsp; in order to have better control of the output format, we can the format function in Excel VBA. The Format function is a very useful function as it can display the numeric values in various forms. There are two types of Format function, one of them is the built-in or predefined format while another one can be defined by the users.<\/p>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9639157585\"><\/ins><br>\n<script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>9.1 Predefined Format function<\/strong><\/h3>\n\n\n\n<p>The syntax &nbsp;of the predefined Format function is<\/p>\n\n\n\n<p><strong>Format (n, \u201cstyle argument\u201d)<\/strong><\/p>\n\n\n\n<p>where n is a number and the list of style arguments are listed in Table 9.1<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><figure><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-357\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg\" alt=\"Excel VBA\" width=\"680\" height=\"469\"><\/a><\/figure><strong>Table 9.1<\/strong><\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 9.1<\/strong><\/h4>\n\n\n\n<p>Private Sub CommandButton1_Click()<br>\nCells(1, 1) = Format(8972.234, &#8220;General Number&#8221;)<br>\nCells(2, 1) = Format(8972.2, &#8220;Fixed&#8221;)<br>\nCells(3, 1) = Format(6648972.265, &#8220;Standard&#8221;)<br>\nCells(4, 1) = Format(6648972.265, &#8220;Currency&#8221;)<br>\nCells(5, 1) = Format(0.56324, &#8220;Percent&#8221;)<br>\nEnd Sub<\/p>\n\n\n\n<p>The Output is shown in Figure 9.1<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_example9.1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"302\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_example9.1.jpg\" alt=\"Excel VBA\" class=\"wp-image-358\"\/><\/a><\/figure><\/div>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<strong>Figure 9.1<\/strong><\/p>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9639157585\"><\/ins><br>\n<script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><br>\n<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>9.2&nbsp;user-defined Format function<\/strong><\/h4>\n\n\n\n<p>The syntax of the user-defined Format function is<\/p>\n\n\n\n<p><strong>Format (n, \u201cuser\u2019s format\u201d)<\/strong><\/p>\n\n\n\n<p>Although it is known as user-defined format, we still need to follow certain formatting styles. Examples of user-defined formatting style are listed in Table 9.2<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.2.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"323\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.2.jpg\" alt=\"vba_table9.2\" class=\"wp-image-362\"\/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Table 9.2<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 9.2<\/strong><\/h4>\n\n\n\n<p>Private Sub CommandButton1_Click()<\/p>\n\n\n\n<p>Cells(1, 1) = Format(781234.57, &#8220;0&#8221;)<br>\nCells(2, 1) = Format(781234.57, &#8220;0.0&#8221;)<br>\nCells(3, 1) = Format(781234.576, &#8220;0.00&#8221;)<br>\nCells(4, 1) = Format(781234.576, &#8220;#,##0.00&#8221;)<br>\nCells(5, 1) = Format(781234.576, &#8220;$#,##0.00&#8221;)<br>\nCells(6, 1) = Format(0.576, &#8220;0%&#8221;)<br>\nCells(7, 1) = Format(0.5768, &#8220;0.00%&#8221;)<\/p>\n\n\n\n<p>End Sub\n<\/p>\n\n\n\n<p>The output is shown in Figure 9.2<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_figure9.2.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"241\" height=\"342\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_figure9.2.jpg\" alt=\"vba_figure9.2\" class=\"wp-image-364\"\/><\/a><\/figure><\/div>\n\n\n\n<p>&nbsp;<strong>Figure 9.2<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-8-string-functions\/\">&lt;&lt;Lesson 8&gt;&gt;<\/a><a href=\"http:\/\/excelvbatutor.com\/index.php\/tutorial\/\">&nbsp;[Contents]<\/a>&nbsp;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-10-financial-functions\/\">&lt;&lt;Lesson 10&gt;&gt;<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>&lt;&lt;Lesson 8&gt;&gt; [Contents] &lt;&lt;Lesson 10&gt;&gt; We need to format the output of an Excel VBA code so the users can understand it easily. In the previous lesson, we have learned a few basic formatting functions like&nbsp;Int, Fix and Round. However,&nbsp; in order to have better control of the output format, we can the format function &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-9\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel VBA Lesson 9: Formatting Functions&#8221;<\/span><\/a><\/p>\n","protected":false},"author":5012,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[22,14],"tags":[],"class_list":["post-353","page","type-page","status-publish","hentry","category-formatting","category-function"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Excel VBA Lesson 9: Formatting Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\n<meta name=\"description\" content=\"This Excel VBA Lesson illustrates formatting output in Excel VBA using the format functions\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/excelvbatutor.com\/vba_lesson9.htm\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Excel VBA Lesson 9: Formatting Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"This Excel VBA Lesson illustrates formatting output in Excel VBA using the format functions\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/vba_lesson9.htm\" \/>\n<meta property=\"og:site_name\" content=\"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-23T11:02:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"680\" \/>\n\t<meta property=\"og:image:height\" content=\"469\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-9\/\",\"url\":\"https:\/\/excelvbatutor.com\/vba_lesson9.htm\",\"name\":\"Excel VBA Lesson 9: Formatting Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\",\"isPartOf\":{\"@id\":\"https:\/\/excelvbatutor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson9.htm#primaryimage\"},\"image\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson9.htm#primaryimage\"},\"thumbnailUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg\",\"datePublished\":\"2013-02-28T10:19:20+00:00\",\"dateModified\":\"2020-04-23T11:02:36+00:00\",\"description\":\"This Excel VBA Lesson illustrates formatting output in Excel VBA using the format functions\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson9.htm#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/vba_lesson9.htm\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson9.htm#primaryimage\",\"url\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg\",\"contentUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg\",\"width\":680,\"height\":469},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson9.htm#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel VBA Lesson 9: Formatting Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/excelvbatutor.com\/#website\",\"url\":\"https:\/\/excelvbatutor.com\/\",\"name\":\"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\",\"description\":\"Master Excel VBA with free tutorials, examples, and personalized guidance. Perfect for beginners and advanced users looking to automate Excel.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Excel VBA Lesson 9: Formatting Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"This Excel VBA Lesson illustrates formatting output in Excel VBA using the format functions","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/excelvbatutor.com\/vba_lesson9.htm","og_locale":"en_US","og_type":"article","og_title":"Excel VBA Lesson 9: Formatting Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"This Excel VBA Lesson illustrates formatting output in Excel VBA using the format functions","og_url":"https:\/\/excelvbatutor.com\/vba_lesson9.htm","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2020-04-23T11:02:36+00:00","og_image":[{"width":680,"height":469,"url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg","type":"image\/jpeg"}],"twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-9\/","url":"https:\/\/excelvbatutor.com\/vba_lesson9.htm","name":"Excel VBA Lesson 9: Formatting Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","isPartOf":{"@id":"https:\/\/excelvbatutor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson9.htm#primaryimage"},"image":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson9.htm#primaryimage"},"thumbnailUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg","datePublished":"2013-02-28T10:19:20+00:00","dateModified":"2020-04-23T11:02:36+00:00","description":"This Excel VBA Lesson illustrates formatting output in Excel VBA using the format functions","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson9.htm#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/vba_lesson9.htm"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/excelvbatutor.com\/vba_lesson9.htm#primaryimage","url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg","contentUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/02\/vba_table9.1.jpg","width":680,"height":469},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/vba_lesson9.htm#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel VBA Lesson 9: Formatting Functions"}]},{"@type":"WebSite","@id":"https:\/\/excelvbatutor.com\/#website","url":"https:\/\/excelvbatutor.com\/","name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"Master Excel VBA with free tutorials, examples, and personalized guidance. Perfect for beginners and advanced users looking to automate Excel.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/users\/5012"}],"replies":[{"embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/comments?post=353"}],"version-history":[{"count":33,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/353\/revisions"}],"predecessor-version":[{"id":3475,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/353\/revisions\/3475"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}