{"id":2398,"date":"2026-10-29T16:35:24","date_gmt":"2026-10-29T08:35:24","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2398"},"modified":"2026-03-29T10:17:14","modified_gmt":"2026-03-29T10:17:14","slug":"how-to-use-rangefillleft-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangefillleft-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.FillLeft in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>FillLeft<\/code> method in xlwings provides a powerful way to replicate data or formulas from the rightmost cell of a specified range into the cells to its left. This functionality is directly modeled after the <code>Range.FillLeft<\/code> method from the Excel Object Model. It is particularly useful for quickly populating adjacent cells with consistent data, extending a series, or copying formulas across a row without manually dragging the fill handle. In data preparation and formatting tasks, using <code>FillLeft<\/code> via xlwings automates these processes, making scripts more efficient and less error-prone compared to manual Excel operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax and Parameters<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In xlwings, the <code>FillLeft<\/code> method is called on a Range object. The basic syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Range.fill_left()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notably, the xlwings implementation of <code>FillLeft<\/code> does not accept parameters in the same way the native Excel VBA method does. In VBA, <code>Range.FillLeft<\/code> has an optional parameter. However, in xlwings, the method is parameterless. The behavior is determined entirely by the range you apply it to. The range defines the destination area to be filled. The rightmost cell of this range acts as the source cell. The method then fills the contents and formatting from this source cell leftwards into the rest of the cells within the specified range.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To control the scope of the fill, you define the target range. For example, if you select a horizontal range of 5 cells (e.g., <code>B1:F1<\/code>), calling <code>fill_left()<\/code> will copy the value\/formula from cell <code>F1<\/code> (the rightmost cell) into cells <code>E1<\/code>, <code>D1<\/code>, <code>C1<\/code>, and <code>B1<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are practical examples demonstrating the use of <code>Range.fill_left()<\/code> in xlwings:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Filling Constant Values:<\/strong><br>This example sets a value in the rightmost cell and fills it to the left.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active workbook and sheet\nwb = xw.books.active\nsht = wb.sheets&#91;'Sheet1']\n\n# Set a value in cell E1\nsht.range('E1').value = 100\n# Define the range from B1 to E1 and fill left from E1\nsht.range('B1:E1').fill_left()\n# Now cells B1, C1, D1 will all contain the value 100<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Filling Formulas:<\/strong><br>This example shows how to propagate a formula leftwards.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwb = xw.books.active\nsht = wb.sheets&#91;0]\n\n# Assume column F has numbers. Put a SUM formula in G1 that sums F1:F10.\nsht.range('G1').formula = '=SUM(F1:F10)'\n# Fill this formula left into cells D1, E1, and F1.\n# The range D1:G1 defines G1 as the source.\nsht.range('D1:G1').fill_left()\n# Cell D1 will now contain =SUM(A1:A10), E1 will have =SUM(B1:B10), etc.,\n# as Excel adjusts the formula references relatively.<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Using with a Variable Range:<\/strong><br>This example uses a variable to define the range dynamically.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwb = xw.books.active\nsht = wb.sheets&#91;'Data']\n\n# Find the last used column in row 3\nlast_col = sht.range('A3').end('right').column\n# Create a range from column 2 to the last column in row 3\nfill_range = sht.range((3, 2), (3, last_col))\n# Perform the fill left operation\nfill_range.fill_left()\n# This will copy the content from the last cell in row 3 to all preceding cells in the defined range.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `FillLeft` method in xlwings provides a powerful way to replicate data or formulas from the righ&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2398","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2398","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=2398"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2398\/revisions"}],"predecessor-version":[{"id":3648,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2398\/revisions\/3648"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}