{"id":2400,"date":"2026-10-30T15:27:20","date_gmt":"2026-10-30T07:27:20","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2400"},"modified":"2026-03-29T10:18:06","modified_gmt":"2026-03-29T10:18:06","slug":"how-to-use-rangefillup-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangefillup-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.FillUp in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The FillUp method in Excel&#8217;s Range object is a powerful tool for data manipulation, allowing users to propagate values, formulas, or formatting from the bottom of a specified range upward to fill empty cells. This is particularly useful for completing datasets where information is missing in the upper cells but present in the lower ones, essentially performing a reverse fill operation compared to the more common FillDown. In xlwings, this functionality is accessed through the <code>api<\/code> property, which provides direct access to the underlying Excel object model, enabling precise and programmatic control over workbook operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality<\/strong><br>The primary function of the <code>FillUp<\/code> method is to copy the content and formatting from the last cell(s) in a range into the preceding empty cells within that same range. It operates on a <code>Range<\/code> object, which can represent a single cell, a row, a column, or a multi-cell block. This method is invaluable for cleaning and preparing data, especially when dealing with reports where summary or total values at the bottom need to be applied to empty detail rows above.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings<\/strong><br>In xlwings, you invoke this method via the Excel VBA object model interface. The syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>range.api.FillUp()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>range<\/code> is an xlwings Range object. The <code>FillUp<\/code> method does not take any parameters. It acts directly on the range it is called upon. The key aspect is the definition of the range: the bottom-most cell(s) of this range must contain the data you want to propagate upward. The method will fill all cells above within the range until it encounters a non-empty cell or reaches the top of the range.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Example<\/strong><br>Consider a scenario where you have a column of data in Excel, but only the last cell (the total) has a value or formula, and you need to fill that upward to all empty cells in the column.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel workbook and sheet\napp = xw.apps.active\nwb = app.books.active\nsheet = wb.sheets&#91;'Sheet1']\n\n# Define the target range. For example, column A from row 1 to row 10.\n# Assume cell A10 contains the value \"Total\" or a formula like \"=SUM(A1:A9)\", and A1:A9 are empty.\ntarget_range = sheet.range('A1:A10')\n\n# Apply the FillUp method\ntarget_range.api.FillUp()\n\n# Now, the value or formula from A10 is copied into cells A1 through A9.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Another practical example involves filling a formula up a column to perform calculations on preceding rows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Start Excel instance and open workbook\nwith xw.App(visible=False) as app:\nwb = app.books.open('data_workbook.xlsx')\nsheet = wb.sheets&#91;0]\n\n# Suppose we want a 10% increase calculation. We put the formula in the bottom cell.\n# Cell B10 contains the formula: =A10*1.1\nsheet.range('B10').formula = '=A10*1.1'\n\n# We want to apply this same formula to cells B1 through B9.\nfill_range = sheet.range('B1:B10')\nfill_range.api.FillUp()\n\n# After execution, cells B1:B9 will contain formulas like =A1*1.1, =A2*1.1, etc.\nwb.save()\nwb.close()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The FillUp method in Excel&apos;s Range object is a powerful tool for data manipulation, allowing users t&#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-2400","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2400","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=2400"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2400\/revisions"}],"predecessor-version":[{"id":3651,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2400\/revisions\/3651"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}