{"id":2388,"date":"2026-10-24T16:13:41","date_gmt":"2026-10-24T08:13:41","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2388"},"modified":"2026-03-29T10:10:53","modified_gmt":"2026-03-29T10:10:53","slug":"how-to-use-rangecut-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangecut-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.Cut in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Range.Cut<\/code> method in Excel&#8217;s object model is a powerful tool for moving a range of cells to a new location, effectively performing a cut-and-paste operation. In xlwings, this functionality is exposed through the <code>cut<\/code> method of a <code>Range<\/code> object. It is particularly useful when you need to relocate data while preserving cell formatting, formulas, or other properties, as it mimics the standard cut action in the Excel user interface.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality<\/strong><br>The primary purpose of the <code>cut<\/code> method is to move the contents and formatting of a specified range to a different range or destination. Unlike a simple copy, a cut operation typically removes the original data from its source location after pasting, though in xlwings, the behavior aligns with Excel&#8217;s programmatic actions where the source range remains until the cut is pasted elsewhere. This method is often used in data reorganization, report generation, or when integrating data from multiple sheets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax<\/strong><br>In xlwings, the syntax for the <code>cut<\/code> method is straightforward:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Range.cut(destination=None)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>destination<\/strong> (optional): This parameter specifies the target range where the cut cells will be pasted. It can be a <code>Range<\/code> object or a string representing the cell address (e.g., <code>\"A1\"<\/code> or <code>\"Sheet2!B5\"<\/code>). If omitted, the cut range is placed on the clipboard, and you would need to use the <code>paste<\/code> method separately to complete the operation. In practice, providing a destination directly is more efficient for automation.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Usage<\/strong><br>Here is a practical example demonstrating the use of <code>cut<\/code> in xlwings. Suppose you have an Excel workbook with data in a range that needs to be moved to another location within the same worksheet or a different one.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel workbook\nwb = xw.books.active\nsheet = wb.sheets&#91;'Sheet1']\n\n# Define the source range to cut (e.g., cells A1 to C3)\nsource_range = sheet.range('A1:C3')\n\n# Cut the source range and paste it to a new destination (e.g., starting at E1)\nsource_range.cut(destination=sheet.range('E1'))\n\n# Alternatively, cut without specifying a destination and then paste\nsource_range.cut() # Cuts to clipboard\nsheet.range('G1').paste() # Pastes from clipboard to G1\n\n# For moving to another sheet, specify the sheet in the destination\nother_sheet = wb.sheets&#91;'Sheet2']\nsource_range.cut(destination=other_sheet.range('A1'))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Range.Cut` method in Excel&apos;s object model is a powerful tool for moving a range of cells to a n&#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-2388","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2388","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=2388"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2388\/revisions"}],"predecessor-version":[{"id":3635,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2388\/revisions\/3635"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}