{"id":1393,"date":"2013-12-12T23:50:16","date_gmt":"2013-12-12T23:50:16","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=1393"},"modified":"2019-04-19T07:49:22","modified_gmt":"2019-04-19T07:49:22","slug":"excel-vba-2010-lesson-19-the-worksheet-object","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/","title":{"rendered":"Excel 2010 VBA Lesson 19: The Worksheet Object"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-18-the-range-object\/\">[Lesson 18]<\/a>&lt;&lt;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-tutorial\/\">[Table of Contents]<\/a>&gt;&gt;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-20-the-workbook-object\/\">[Lesson 20]<\/a><\/strong><\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><b>19.1 The Worksheet Properties in Excel 2010 VBA&nbsp;<\/b><\/h4>\n\n\n\n<p>Similar to the Range Object, the Worksheet has its own set of properties and methods. When we write Excel 2010 VBA &nbsp;code involving the Worksheet object, we use&nbsp;<i>Worksheets<\/i>.<\/p>\n\n\n\n<script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\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>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<p>Some of the common properties of the worksheet are name<i>, count, cells, columns, rows<\/i>&nbsp;and&nbsp;<i>columnWidth.<\/i><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example 19.1<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n MsgBox Worksheets(1).Name\nEnd Sub\n<\/pre>\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>\nRunning the code will produce a pop-up dialog that displays the worksheet name as sheet 1, as shown in Figure 19.1.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.1.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>Figure 19.1<\/strong><\/p>\n\n\n\n<p>The count property returns the number of worksheets in an opened workbook.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example 19.2<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n MsgBox Worksheets.Count\nEnd Sub\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.2.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p><br>\n<strong>Figure 19.2: The runtime screen<\/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><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><b>Example 19.3<\/b><\/h4>\n\n\n\n<p>The count property in this example will return the number of columns in the worksheet.\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n MsgBox Worksheets(1).Columns.Count\nEnd Sub\n<\/pre>\n\n\n\n<p>The output is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.3.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>Figure 19.3<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example 19.4<\/strong><\/h4>\n\n\n\n<p>The count property in this example will return the number of rows in the worksheet.\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n MsgBox Worksheets(1).Rows.Count\nEnd Sub\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.4.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>Figure 19.4<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><b>19.2 The Worksheet Methods<\/b><\/h4>\n\n\n\n<p>Some of the worksheet methods are&nbsp;<i>add, delete, select, SaveAs, copy, paste<\/i>&nbsp;and more.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><b><\/b><b>Example 19.5<\/b><\/h4>\n\n\n\n<p>In this example, when the user clicks the first command button, it will add a new sheet to the workbook. When the user clicks the second command button, it will delete the new worksheet that has been added earlier.\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n Worksheets. Add\nEnd Sub\n\nPrivate Sub CommandButton2_Click()\n Worksheets(1).Delete\nEnd Sub\n<\/pre>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br>\n<!-- Excel VBA Responsive --><br>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"2763751108\" data-ad-format=\"rectangle\"><\/ins><br>\n<script><br \/>\n(adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><b>Example 19.6<\/b><\/h4>\n\n\n\n<p>The select method associated with worksheet lets the user select a particular worksheet. In this example, worksheet 2 will be selected.\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n\u2018Worksheet 2 will be selected\n Worksheets(2).Select\nEnd Sub\n<\/pre>\n\n\n\n<p>The select method can also be used together with the Worksheet\u2019s properties Cells, Columns, and Rows as shown in the following examples.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><b>Example 19.7<\/b><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n\u2018Cell A1 will be selected\n Worksheets (1).Cells (1).Select\nEnd Sub\n<\/pre>\n\n\n\n<p><b>Example 19.8<\/b>\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n\u2018Column 1 will be selected\n Worksheets (1).Columns (1).Select\nEnd Sub\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><b>Example 19.9<\/b><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n\u2018Row 1 will be selected\n Worksheets (1).Rows (1).Select\nEnd Sub\n<\/pre>\n\n\n\n<p>Excel VBA 2010 also allows us to write code for copy and paste. Let\u2019s look at the following Example:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><b>&nbsp;<\/b><b>Example 19.10<\/b>\n<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Private Sub CommandButton1_Click()\n\u2018To copy the content of a cell 1\n Worksheets(1).Cells(1).Select\n Selection.Copy\nEnd Sub\n\nPrivate Sub CommandButton2_Click()\n\u2018To paste the content of cell 1 to cell 2\n Worksheets(1).Cells(2).Select\n ActiveSheet.Paste\nEnd Sub\n<\/pre>\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\">&nbsp;<strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-18-the-range-object\/\">[Lesson 18]<\/a>&lt;&lt;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-tutorial\/\">[Table of Contents]<\/a>&gt;&gt;<a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-20-the-workbook-object\/\">[Lesson 20]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;[Lesson 18]&lt;&lt;[Table of Contents]&gt;&gt;[Lesson 20] 19.1 The Worksheet Properties in Excel 2010 VBA&nbsp; Similar to the Range Object, the Worksheet has its own set of properties and methods. When we write Excel 2010 VBA &nbsp;code involving the Worksheet object, we use&nbsp;Worksheets. Some of the common properties of the worksheet are name, count, cells, columns, rows&nbsp;and&nbsp;columnWidth. &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel 2010 VBA Lesson 19: The Worksheet Object&#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":[10],"tags":[],"class_list":["post-1393","page","type-page","status-publish","hentry","category-object"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Excel 2010 VBA Lesson 19: The Worksheet Object - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\n<meta name=\"description\" content=\"This lesson describes how to work with the worksheet object of excel 2010 VBA\" \/>\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\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Excel 2010 VBA Lesson 19: The Worksheet Object - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"This lesson describes how to work with the worksheet object of excel 2010 VBA\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/\" \/>\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=\"2019-04-19T07:49:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.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-2010-lesson-19-the-worksheet-object\/\",\"url\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/\",\"name\":\"Excel 2010 VBA Lesson 19: The Worksheet Object - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\",\"isPartOf\":{\"@id\":\"https:\/\/excelvbatutor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.1.jpg\",\"datePublished\":\"2013-12-12T23:50:16+00:00\",\"dateModified\":\"2019-04-19T07:49:22+00:00\",\"description\":\"This lesson describes how to work with the worksheet object of excel 2010 VBA\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#primaryimage\",\"url\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.1.jpg\",\"contentUrl\":\"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.1.jpg\",\"width\":154,\"height\":141},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel 2010 VBA Lesson 19: The Worksheet Object\"}]},{\"@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 2010 VBA Lesson 19: The Worksheet Object - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"This lesson describes how to work with the worksheet object of excel 2010 VBA","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\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/","og_locale":"en_US","og_type":"article","og_title":"Excel 2010 VBA Lesson 19: The Worksheet Object - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"This lesson describes how to work with the worksheet object of excel 2010 VBA","og_url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2019-04-19T07:49:22+00:00","og_image":[{"url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.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-2010-lesson-19-the-worksheet-object\/","url":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/","name":"Excel 2010 VBA Lesson 19: The Worksheet Object - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","isPartOf":{"@id":"https:\/\/excelvbatutor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#primaryimage"},"image":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#primaryimage"},"thumbnailUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.1.jpg","datePublished":"2013-12-12T23:50:16+00:00","dateModified":"2019-04-19T07:49:22+00:00","description":"This lesson describes how to work with the worksheet object of excel 2010 VBA","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#primaryimage","url":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.1.jpg","contentUrl":"https:\/\/excelvbatutor.com\/wp-content\/uploads\/2013\/03\/vba_Figure16.1.jpg","width":154,"height":141},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-2010-lesson-19-the-worksheet-object\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel 2010 VBA Lesson 19: The Worksheet Object"}]},{"@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\/1393","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=1393"}],"version-history":[{"count":52,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1393\/revisions"}],"predecessor-version":[{"id":3328,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/1393\/revisions\/3328"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=1393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=1393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=1393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}