{"id":36,"date":"2026-02-02T11:01:16","date_gmt":"2026-02-02T03:01:16","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=36"},"modified":"2026-01-17T05:04:11","modified_gmt":"2026-01-17T05:04:11","slug":"how-to-expand-the-reference-to-cell-ranges-in-the-current-worksheet-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-expand-the-reference-to-cell-ranges-in-the-current-worksheet-using-xlwings\/","title":{"rendered":"How To Expand the Reference to Cell Ranges in the Current Worksheet Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>#xlwings<\/p>\n<p>sht.range(&#8216;C2&#8217;).resize(3).select()\u00a0\u00a0\u00a0\u00a0 #Create a cell range C2:C4<\/p>\n<p>#sht.range(&#8216;C2&#8217;).resize(1, 3).select()\u00a0\u00a0\u00a0 #Create a cell range C2:E2<\/p>\n<p>#sht.range(&#8216;C2&#8217;).resize(3, 3).select()\u00a0\u00a0\u00a0 #Create a cell range C2:E4<\/p>\n<p>\u00a0<\/p>\n<p>#expand method<\/p>\n<p>#sht.range(&#8216;C4&#8217;).expand(&#8216;table&#8217;).select()<\/p>\n<p>#sht.range(&#8216;C4&#8217;).expand().select()\u00a0\u00a0\u00a0 #Equivalent to the method above<\/p>\n<p>#sht.range(&#8216;C4&#8217;).expand(&#8216;down&#8217;).select()<\/p>\n<p>#sht.range(&#8216;C4&#8217;).expand(&#8216;right&#8217;).select()<\/p>\n<p>\u00a0<\/p>\n<p>#xlwings API<\/p>\n<p>#sht.api.Range(&#8216;C2&#8217;, sht.api.Range(&#8216;C2&#8217;).Resize(3)).Select()<\/p>\n<p>#sht.api.Range(&#8216;C2&#8217;, sht.api.Range(&#8216;C2&#8217;).Resize(1, 3)).Select()<\/p>\n<p>#sht.api.Range(&#8216;C2&#8217;, sht.api.Range(&#8216;C2&#8217;).Resize(3, 3)).Select()<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Expand the reference to the current worksheet's cell range\n\nimport xlwings as xw    #Import the xlwings package\n\napp=xw.App()\nbk=app.books.active    #Get the active workbook\nsht=bk.sheets.active    #Get the active worksheet\n\n#xlwings\nsht.range('C2').resize(3).select()     #Create a cell range C2:C4\n#sht.range('C2').resize(1, 3).select()    #Create a cell range C2:E2\n#sht.range('C2').resize(3, 3).select()    #Create a cell range C2:E4\n\n#expand method\n#sht.range('C4').expand('table').select()\n#sht.range('C4').expand().select()    #Equivalent to the method above\n#sht.range('C4').expand('down').select()\n#sht.range('C4').expand('right').select()\n\n#xlwings API\n#sht.api.Range('C2', sht.api.Range('C2').Resize(3)).Select()\n#sht.api.Range('C2', sht.api.Range('C2').Resize(1, 3)).Select()\n#sht.api.Range('C2', sht.api.Range('C2').Resize(3, 3)).Select()\n\n#bk.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/19.png\" alt=\"Expand the Reference to Cell Ranges in the Current Worksheet Using xlwings\" class=\"wp-image-287\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/19.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/19-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/19-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/20.png\" alt=\"\" class=\"wp-image-288\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/20.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/20-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/20-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/21.png\" alt=\"\" class=\"wp-image-289\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/21.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/21-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/21-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-xlwings-cell-range"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":290,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/36\/revisions\/290"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}