向下和向右智能自動填充

內容

直到現在,有時我會面帶微笑地記得 10 年前我第一次參加現場企業培訓。

Imagine: the open space office of the representative office of an international FMCG company, huge as a football field. Chic design, expensive office equipment, dress code, expats cooing in the corners – that’s all 🙂 In one of the meeting rooms, I start a two-day advanced training on the then current version of Excel 2003 for 15 key employees of the economic department, along with their leader. We get acquainted, I ask them about business tasks, problems, I ask them to show several typical work files. They show the kilometer length of unloading from SAP, the sheets of reports that they make on this, etc. Well, it’s a familiar thing – I mentally figure out topics and timing, adjust to the audience. Out of the corner of my eye, I notice how one of the participants, demonstrating a piece of his report, patiently pulls the cell with the formula down by the black cross in the lower right corner for several thousand lines, then skips the end of the table on the fly, pulls it back, etc. Unable to stand it, I interrupt him curling the mouse around the screen and show a double-click on the black cross, explaining about auto-completion down to the stop. 

突然,我意識到觀眾安靜得可疑,每個人都在奇怪地看著我。 我不知不覺地環顧四周——一切都很好,我的胳膊和腿都在原位,我的蒼蠅被扣上了。 我在心裡回想我的遺言,尋找一些可怕的條款——似乎沒有什麼犯罪行為。 說完,團長默默起身,握了握我的手,面無表情地說:“謝謝你,尼古拉。 本次培訓即可完成。

好吧,簡而言之,事實證明他們都沒有關於雙擊黑色十字和自動完成的線索。 不知何故,歷史上沒有人向他們展示如此簡單但必要的東西。 整個部門為數千行手動提取公式,可憐的傢伙。 我在這裡。 石油場景。 然後部門負責人非常要求不要向任何人透露他們公司的名稱🙂

幾次之後,也出現了類似的情況,但只是針對個別聽眾——當然,現在大多數人都知道這個功能。 

向下和向右智能自動填充問題是不同的。 在掌握瞭如此美妙的功能的第一次快樂之後,大多數用戶開始明白通過雙擊黑色十字(自動完成標記)自動複製公式具有所有積極方面和消極方面:

  • 複製並不總是發生在表的末尾. 如果表格不是單片的,即相鄰列中有空單元格,那麼自動完成將不會工作到表格末尾。 最有可能的是,該過程將在到達終點之前在最近的空單元格處停止。 如果列下方的某些單元格被某些單元格佔用,則自動完成將完全停止它們。
  • 複印時 細胞設計破壞,因為默認情況下,不僅複製公式,還復制格式。 要更正,請單擊複製選項按鈕並選擇 只有價值觀 (無格式填寫).
  • 沒有快速的方法來方便地拉伸公式 不是向下而是向右除了用手拉。 雙擊黑色十字就可以了。

讓我們嘗試用一個簡單的宏來解決這些缺點。

向左按鍵盤快捷鍵 Alt + F11鍵 或按鈕 Visual Basic中 選項卡 開發人員 (開發商). 通過菜單插入新的空模塊 插入 - 模塊 並在那裡複製這些宏的文本:

Sub SmartFillDown() Dim rng As Range, n As Long Set rng = ActiveCell.Offset(0, -1).CurrentRegion If rng.Cells.Count > 1 Then n = rng.Cells(1).Row + rng.Rows。 Count - ActiveCell.Row ActiveCell.AutoFill Destination:=ActiveCell.Resize(n, 1), Type:=xlFillValues End If End Sub Sub SmartFillRight() Dim rng As Range, n As Long Set rng = ActiveCell.Offset(-1, 0).CurrentRegion If rng.Cells.Count > 1 Then n = rng.Cells(1).Column + rng.Columns.Count - ActiveCell.Column ActiveCell.AutoFill Destination:=ActiveCell.Resize(1, n),輸入: =xlFillValues End If End Sub  

這樣的宏:

  • 不僅可以向下填充(SmartFillDown),還可以向右填充(SmartFillRight)
  • 不要破壞下方或右側單元格的格式 - 僅複製公式(值)
  • 空的相鄰單元格將被忽略,並且複制恰好發生在表的末尾,而不是數據中最近的間隙或第一個佔用的單元格。

為了更方便,您可以使用 按鈕為這些宏分配鍵盤快捷鍵 宏 - 選項 (宏 - 選項) 就在標籤上。 開發人員 (開發商). 現在只需在列的第一個單元格中輸入所需的公式或值,然後按下宏的指定組合鍵即可自動填充整列(或行):

美:

PS 隨著“智能表格”的出現,將公式複製到表格末尾的部分問題在 Excel 2007 中得到了解決。 誠然,它們並不總是,也並非無處不在。 在右邊,Excel 從來沒有學會自己複製。

  • 什麼是宏,如何使用它們,從哪裡獲取 Visual Basic 代碼以及在哪裡粘貼。
  • Excel 2007-2013 中的智能表格
  • 複製沒有鏈接移位的公式

發表評論