{"id":30,"date":"2026-01-30T11:14:26","date_gmt":"2026-01-30T03:14:26","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=30"},"modified":"2026-01-17T04:50:02","modified_gmt":"2026-01-17T04:50:02","slug":"how-to-reference-cells-in-a-cell-range-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-reference-cells-in-a-cell-range-using-xlwings\/","title":{"rendered":"How To Reference Cells In a Cell Range Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<h3>Coordinate Index<\/h3>\n<p>#xlwings<\/p>\n<p>rng=sht.range(&#8216;B2:D5&#8217;)<\/p>\n<p>rng[0,0].select()\u00a0\u00a0\u00a0 #B2\uff0cNote: The index is 0-based<\/p>\n<p>\u00a0<\/p>\n<p>#xlwings API<\/p>\n<p>#rng=sht.api.Range(&#8216;B2:D5&#8217;)<\/p>\n<p>#rng(1,1).Select()<\/p>\n<p>\u00a0<\/p>\n<h3>Linear Index<\/h3>\n<p>#xlwings<\/p>\n<p>#rng=sht.range(&#8216;B2:D5&#8217;)<\/p>\n<p>#rng[2].select()<\/p>\n<p>\u00a0<\/p>\n<p>#xlwings API<\/p>\n<p>#rng=sht.api.Range(&#8216;B2:D5&#8217;)<\/p>\n<p># rng(3).Select()<\/p>\n<p>\u00a0<\/p>\n<h3>Slicing<\/h3>\n<p>#xlwings<\/p>\n<p>#rng=sht.range(&#8216;B2:D5&#8217;)<\/p>\n<p>#rng[1:3,1:3].select()\u00a0\u00a0\u00a0 #Slicing C3:D4<\/p>\n<p>#rng[:,2].select()\u00a0\u00a0\u00a0\u00a0 #Slicing\u00a0 D2:D5<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Referencing Cells Within a 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#Coordinate Index\n#xlwings\nrng=sht.range('B2:D5')\nrng&#91;0,0].select()    #B2\uff0cNote: The index is 0-based\n\n#xlwings API\n#rng=sht.api.Range('B2:D5')\n#rng(1,1).Select()\n\n#Linear Index\n#xlwings\n#rng=sht.range('B2:D5')\n#rng&#91;2].select()\n\n#xlwings API\n#rng=sht.api.Range('B2:D5')\n# rng(3).Select()\n\n#Slicing\n#xlwings\n#rng=sht.range('B2:D5')\n#rng&#91;1:3,1:3].select()    #Slicing C3:D4\n#rng&#91;:,2].select()     #Slicing  D2:D5\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\/01\/12.png\" alt=\"Reference Cells In a Cell Range Using xlwings\" class=\"wp-image-267\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/01\/12.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/01\/12-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/01\/12-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-30","post","type-post","status-publish","format-standard","hentry","category-xlwings-cell-range"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/30","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=30"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":268,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/30\/revisions\/268"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}