{"id":2883,"date":"2017-10-11T00:36:56","date_gmt":"2017-10-11T00:36:56","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=2883"},"modified":"2020-04-23T11:01:47","modified_gmt":"2020-04-23T11:01:47","slug":"excel-vba-lesson-7-trigonometric-functions","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-7-trigonometric-functions\/","title":{"rendered":"Excel VBA Lesson 7: Trigonometric Functions"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-6-mathematical-functions\/\">&lt;&lt;Lesson 6&gt;&gt;<\/a><a href=\"http:\/\/excelvbatutor.com\/index.php\/tutorial\/\"> [Contents] <\/a><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-8-string-functions\/\">&lt;&lt;Lesson 8&gt;&gt;<\/a><\/strong><\/h4>\n\n\n\n<p>In the previous lesson, we have learned how to write code using various mathematical functions in Excel VBA. In this lesson, we shall proceed to learn how to work with trigonometric functions.The three basic trigonometric functions are Sin, Cos and Tan which stand for sine, cosine and tangent. We also deal with the inverse of tangent, Atn.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7.1 The Sin function<\/h3>\n\n\n\n<p>The Sin function returns the sine value of an angle. We need to convert the angle to radian as Excel VBA cannot deal with the angle in degree.<br>\nThe conversion is based on the following equation:<\/p>\n\n\n\n<p>\u03c0 radian= 180<sup>o<\/sup><br>\nso 1<sup>o<\/sup>=\u03c0\/180 radian<\/p>\n\n\n\n<p>The issue is how to get the exact value of p? We can use p=3.14159 but it will not be accurate.<br>\nTo get exact value of \u03c0, we use the arc tangent function, i.e. is Atn. Using the equation tan(\u03c0\/4)=1, so Atn(1)=\u03c0\/4, therefore, \u03c0=4Atn(1)<\/p>\n\n\n\n<p>The syntax of the Sin function in Excel VBA is<\/p>\n\n\n\n<p>Sin(Angle in radian)<\/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<h4 class=\"wp-block-heading\">Example 7.1<\/h4>\n\n\n\n<p>In this example, we use pi to represent \u03c0 and assign the value of \u03c0 using the formula pi = 4*.Atn(1). We use the function Round the value of sine to four decimal places.<br>\nPrivate Sub CommandButton1_Click()<br>\nDim pi As Single<\/p>\n\n\n\n<p>pi = 4*.Atn(1)<\/p>\n\n\n\n<p>MsgBox(&#8220;Sin 90 is&#8221; &amp; Round(Sin(pi\/2), 4))<\/p>\n\n\n\n<p>End Sub<\/p>\n\n\n\n<p>Running the program produces the message as shown in Figure 7.1\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Figure 7.1<\/h4>\n\n\n\n<h3 class=\"wp-block-heading\">7.1 The Cos function<\/h3>\n\n\n\n<p>The Cos function returns the cosine value of an angle<\/p>\n\n\n\n<p>The syntax of the Cos function in Excel VBA is<\/p>\n\n\n\n<p>Cos(Angle in radian)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example 7.2<\/h4>\n\n\n\n<p>Private Sub CommandButton1_Click()<br>\nDim pi As Single<\/p>\n\n\n\n<p>pi = 4*.Atn(1)<\/p>\n\n\n\n<p>MsgBox(&#8220;Cos 60 is&#8221; &amp; Round(Cos(pi\/3), 4))<\/p>\n\n\n\n<p>End Sub<br>\nRunning the program produces the message as shown in Figure 7.2\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.2.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Figure 7.2<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-6-mathematical-functions\/\">&lt;&lt;Lesson 6&gt;&gt;<\/a><a href=\"http:\/\/excelvbatutor.com\/index.php\/tutorial\/\"> [Contents] <\/a><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-8\/\">&lt;&lt;Lesson 8&gt;&gt;<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>&lt;&lt;Lesson 6&gt;&gt; [Contents] &lt;&lt;Lesson 8&gt;&gt; In the previous lesson, we have learned how to write code using various mathematical functions in Excel VBA. In this lesson, we shall proceed to learn how to work with trigonometric functions.The three basic trigonometric functions are Sin, Cos and Tan which stand for sine, cosine and tangent. We also &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-7-trigonometric-functions\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel VBA Lesson 7: Trigonometric 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":[14],"tags":[],"class_list":["post-2883","page","type-page","status-publish","hentry","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 7: Trigonometric Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\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_lesson7.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 7: Trigonometric Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"&lt;&lt;Lesson 6&gt;&gt; [Contents] &lt;&lt;Lesson 8&gt;&gt; In the previous lesson, we have learned how to write code using various mathematical functions in Excel VBA. In this lesson, we shall proceed to learn how to work with trigonometric functions.The three basic trigonometric functions are Sin, Cos and Tan which stand for sine, cosine and tangent. We also &hellip; Continue reading &quot;Excel VBA Lesson 7: Trigonometric Functions&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/vba_lesson7.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:01:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\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-7-trigonometric-functions\/\",\"url\":\"https:\/\/excelvbatutor.com\/vba_lesson7.htm\",\"name\":\"Excel VBA Lesson 7: Trigonometric 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_lesson7.htm#primaryimage\"},\"image\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson7.htm#primaryimage\"},\"thumbnailUrl\":\"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg\",\"datePublished\":\"2017-10-11T00:36:56+00:00\",\"dateModified\":\"2020-04-23T11:01:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson7.htm#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/vba_lesson7.htm\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson7.htm#primaryimage\",\"url\":\"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg\",\"contentUrl\":\"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson7.htm#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel VBA Lesson 7: Trigonometric 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 7: Trigonometric Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","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_lesson7.htm","og_locale":"en_US","og_type":"article","og_title":"Excel VBA Lesson 7: Trigonometric Functions - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"&lt;&lt;Lesson 6&gt;&gt; [Contents] &lt;&lt;Lesson 8&gt;&gt; In the previous lesson, we have learned how to write code using various mathematical functions in Excel VBA. In this lesson, we shall proceed to learn how to work with trigonometric functions.The three basic trigonometric functions are Sin, Cos and Tan which stand for sine, cosine and tangent. We also &hellip; Continue reading \"Excel VBA Lesson 7: Trigonometric Functions\"","og_url":"https:\/\/excelvbatutor.com\/vba_lesson7.htm","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2020-04-23T11:01:47+00:00","og_image":[{"url":"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-7-trigonometric-functions\/","url":"https:\/\/excelvbatutor.com\/vba_lesson7.htm","name":"Excel VBA Lesson 7: Trigonometric 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_lesson7.htm#primaryimage"},"image":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson7.htm#primaryimage"},"thumbnailUrl":"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg","datePublished":"2017-10-11T00:36:56+00:00","dateModified":"2020-04-23T11:01:47+00:00","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson7.htm#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/vba_lesson7.htm"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/excelvbatutor.com\/vba_lesson7.htm#primaryimage","url":"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg","contentUrl":"https:\/\/excelvbatutor.com\/vba_img\/figure_L7.1.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/vba_lesson7.htm#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel VBA Lesson 7: Trigonometric 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\/2883","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=2883"}],"version-history":[{"count":8,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/2883\/revisions"}],"predecessor-version":[{"id":3341,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/2883\/revisions\/3341"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=2883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=2883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=2883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}