{"id":2054,"date":"2011-05-08T10:43:28","date_gmt":"2011-05-08T09:43:28","guid":{"rendered":"https:\/\/www.peppercrew.nl\/index.php\/2011\/05\/excel-copying-formulas-with-constraints\/"},"modified":"2011-05-19T15:07:33","modified_gmt":"2011-05-19T14:07:33","slug":"excel-copying-formulas-with-constraints","status":"publish","type":"post","link":"https:\/\/ingmarverheij.com\/en\/excel-copying-formulas-with-constraints\/","title":{"rendered":"Excel : Copying formulas (with) constraints"},"content":{"rendered":"<p>Microsoft Excel is a spreadsheet program that contains one or more worksheets. Each worksheet contains a bunch of cells which are located by a row (1,2,3,etc) and a column (A,B,C,etc).<\/p>\n<p><a class=\"thickbox\" href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image14.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image_thumb14.png\" border=\"0\" alt=\"image\" width=\"244\" height=\"168\" \/><\/a><\/p>\n<p>Each cell can contain data or a formula. With a formula your able to transform the data from other cells to whatever you may need. You\u2019ll probably want to re-use the formula in different rows, columns or worksheets.<\/p>\n<p><!--more--><\/p>\n<p>A formula contains a function (like min, max, average, etc) and a range of data (like A:A or A1:A10).<\/p>\n<p>For example I\u2019ve filled row 1 to 10 on column A with the corresponding numbers.\u00a0 In Cell B1 we\u2019ve created a formula that calculates the average of these 10 cells : =AVERAGE(A1:A10).<\/p>\n<p><a class=\"thickbox\" href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image15.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image_thumb15.png\" border=\"0\" alt=\"image\" width=\"244\" height=\"141\" \/><\/a><\/p>\n<p><em>PS: The screenshot says \u2018gemiddelde\u2019 which is Dutch for average. <\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Now we copy the content of cell B1, which contains the formula, and copy it to cell D5.<\/p>\n<p><a class=\"thickbox\" href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image16.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image_thumb16.png\" border=\"0\" alt=\"image\" width=\"244\" height=\"142\" \/><\/a><\/p>\n<p>The\u00a0 result of cell D5 is \u201cdivision by zero\u201d. When we look at the formula we see that Microsoft Excel transformed both the column and the row corresponding to the location where we moved it (+2 columns, +4 rows).<\/p>\n<p>Altough this might be usefull in some cases, in some cases it isn\u2019t.<\/p>\n<p>&nbsp;<\/p>\n<p>There is a little trick which helps you setting constraints when copying formula\u2019s. The use of the $ sign. If you place a $ sign in front of a column or a row it will become static. It won\u2019t be transformed when you copy the content of a cell.<\/p>\n<p>Let&#8217;s take a look at how this works.<\/p>\n<p>When we change the content of cell B1 to =AVERAGE($A1:$A10) where setting a constraint on the row, row A is now static. When we copy the cell to D5 the formula in D5 will be =AVERAGE($A5:$A14).<\/p>\n<p><a class=\"thickbox\" href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image17.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image_thumb17.png\" border=\"0\" alt=\"image\" width=\"244\" height=\"123\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>When we repeat the same thing but instead of setting a constraint on the row we\u2019re setting a constraint on the column. The content of cell B1 will be = AVERAGE(A$1:A$10).<\/p>\n<p>Now the formula in cell D5 will be =AVERAGE(C$1:C$10). The column is changed, but the row\u2019s are not.<\/p>\n<p><a class=\"thickbox\" href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image18.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image_thumb18.png\" border=\"0\" alt=\"image\" width=\"244\" height=\"141\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now let\u2019s set a constraint on the formula in cell B1 where we make both the column and the row static. The content of cell B1 is =AVERAGE($A$1:$A$10). After copying cell B1 to D5 the both the formula and the result of cell D5 matches B1:<\/p>\n<p><a class=\"thickbox\" href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image19.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2011\/05\/image_thumb19.png\" border=\"0\" alt=\"image\" width=\"244\" height=\"142\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Although it\u2019s very simple and looks non-trivial, the little things like this makes my live a lot easier when working with formulas in Excel.<\/p>\n<p>&nbsp;<\/p>\n<p>Ingmar Verheij<\/p>","protected":false},"excerpt":{"rendered":"<p>Microsoft Excel is a spreadsheet program that contains one or more worksheets. Each worksheet contains a bunch of cells which are located by a row (1,2,3,etc) and a column (A,B,C,etc). Each cell can contain data or a formula. With a formula your able to transform the data from other cells to whatever you may need. [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[17],"tags":[276,277,243,278],"class_list":["post-2054","post","type-post","status-publish","format-standard","hentry","category-office","tag-constraint","tag-copy","tag-excel","tag-formula"],"_links":{"self":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/2054","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/comments?post=2054"}],"version-history":[{"count":3,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/2054\/revisions"}],"predecessor-version":[{"id":2523,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/2054\/revisions\/2523"}],"wp:attachment":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/media?parent=2054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/categories?post=2054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/tags?post=2054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}