提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何根據Excel中的單元格值將整行移動到活動工作表的底部?

根據Excel中的單元格值將整行移動到活動工作表的底部,請嘗試本文中的VBA代碼。

使用VBA代碼根據單元格值將整行移動到活動工作表的底部

Office選項卡在Office中啟用選項卡式編輯和瀏覽,使您的工作更輕鬆......
Kutools for Excel - 最佳辦公生產力工具將解決您的大部分Excel問題
  • 重用任何東西: 將最常用或最複雜的公式,圖表和其他任何內容添加到您的收藏夾中,並在將來快速重複使用它們。
  • 超過20文本功能: 從文本字符串中提取數字; 提取或刪除部分文本; 將數字和貨幣轉換為英語單詞...
  • 合併工具:多個工作簿和表格合二為一; 合併多個單元格/行/列而不丟失數據; 合併重複行和總和...
  • 拆分工具:根據價值將數據拆分為多個表格; 一個工作簿到多個Excel,PDF或CSV文件; 一列到多列......
  • 粘貼跳過 隱藏/過濾行; 數和總和 按背景顏色; 創建郵件列表和 通過Cell的價值發送電子郵件...
  • 超級過濾器: 創建高級過濾方案並應用於任何工作表; 分類 按週,日,頻率等; 過濾 通過大膽,公式,評論......
  • 超過300強大的功能; 適用於Office 2007-2019和365; 支持所有語言; 在公司輕鬆部署; 全功能60天免費試用。

箭頭藍色右泡 使用VBA代碼根據單元格值將整行移動到活動工作表的底部


例如,如下圖所示,如果C列中的某個單元格包含特定值“完成”,則將整行移動到當前工作表的底部。 請做如下。

1。 按 其他+ F11 鍵同時打開 Microsoft Visual Basic for Applications 窗口。

2。 在裡面 Microsoft Visual Basic for Applications 窗口中,單擊 插入 > 模塊。 然後將下面的VBA代碼複製並粘貼到窗口中。

VBA代碼:根據單元格值將整行移動到活動工作表的底部

Sub MoveToEnd()
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xEndRow As Long
    Dim I As Long
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
lOne:
    Set xRg = Application.InputBox("Select range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    If xRg.Columns.Count > 1 Or xRg.Areas.Count > 1 Then
        MsgBox " Multiple ranges or columns have been selected ", vbInformation, "Kutools for Excel"
        GoTo lOne
    End If
    xEndRow = xRg.Rows.Count + xRg.Row
    Application.ScreenUpdating = False
    For I = xRg.Rows.Count To 1 Step -1
        If xRg.Cells(I) = "Done" Then
           xRg.Cells(I).EntireRow.Cut
           Rows(xEndRow).Insert Shift:=xlDown
        End If
    Next
    Application.ScreenUpdating = True
End Sub

注意:在VBA代碼中,“完成“是您將基於整行移動的單元格值。 您可以根據需要進行更改。

3。 按 F5 運行代碼的關鍵,然後彈出 Kutools for Excel 對話框中,選擇某個值所在的列範圍,然後單擊 OK 按鈕。

點擊後 OK 按鈕時,指定列中包含值“完成”的整行將自動移至數據范圍的底部。


箭頭藍色右泡相關文章:


Kutools for Excel - 最佳辦公生產力工具提高80%的生產力

  • 重用: 快速插入 複雜的公式,圖表 以及你以前用過的任何東西; 加密單元格 密碼; 創建郵件列表 並發送電子郵件...
  • 超級方程式酒吧 (輕鬆編輯多行文字和公式); 閱讀佈局 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不丟失數據; 分裂細胞含量; 組合重複的行/列...防止重複的細胞; 比較範圍...
  • 選擇複製或唯一 行; 選擇空行 (所有細胞都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇......
  • 精確複製 多個單元格而不更改公式參考; 自動創建參考 多張表; 插入項目符號,複選框等等......
  • 提取文本,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級過濾器 (將過濾方案保存並應用到其他工作表); 高級排序 按月/週/日,頻率等; 特殊過濾器 用粗體,斜體......
  • 結合工作簿和工作表; 根據鍵列合併表; 將數據拆分為多個表格; 批量轉換xls,xlsx和PDF...
  • 超過300強大的功能。 支持Office / Excel 2007-2019和365。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能60天免費試用。
kte tab 201905

Office選項卡為Office提供選項卡式界面,使您的工作更輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,Publisher,Access,Visio和Project。
  • 在同一窗口的新選項卡中打開並創建多個文檔,而不是在新窗口中。
  • 通過50%提高您的工作效率,每天為您減少數百次鼠標點擊!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Anon · 1 months ago
    Hello, the only way I can get this to work is if I "run" the macro in the Visual Basic sub screen. Is it possible to have this VBA code run automatically, once the user types in "Done"? Each time I'm getting the Kutools for Excel dialog box pop up to ask the parameters I'm requesting the code to search by. I have sort of worked around this by replacing : xTxt = ActiveSheet.UsedRange.AddressLocal with the parameters I need searched and hitting enter. But it would be more convenient if it automatically made the changes after "Done" was entered. Thank you!
  • To post as a guest, your comment is unpublished.
    Tammy · 3 months ago
    Hello, is there a way to tweak this so that it moves a row somewhere else in the same sheet besides the end? I have a sheet that has order information for dated orders and upcoming orders yet to be dated and I have it so that when I put an "X" in column A things highlight and bold depending on part #'s and shipping locations. Now I have to physically cut and paste the newly dated (shipping date) so that it fits in at the top sorted by date (1st thru end of month). I have been able to conditional format everything up to this point, but I don't think I can move rows that way. I was wondering if VBA could do this, move a row when a date is entered to fit in with the other dated rows?
  • To post as a guest, your comment is unpublished.
    Brandon · 8 months ago
    Hello. This is almost perfect for what I want. I have part of the same request as Anon had to make this work without user input along with some extras.

    I am wondering if it is possible to have the only column searched to be i4 to i50 and have it automatically run at open or anytime the i column is edited. Also if it would be possible to move the rows to the bottom of the sheet without any blank rows between "done" rows and "no" rows. Currently if I select i4:i50 and if I only have data up to row 25 it will paste the "done" rows ascending from row 50 instead of row 25. The number of rows in my sheet is constantly changing and shouldn't get to more than 50. Thanks for the help.
    • To post as a guest, your comment is unpublished.
      crystal · 7 months ago
      Hi Brandon,
      Sorry can help you with that. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Mags · 1 years ago
    Hi Crystal, this code works great, thank you. I would like move all the rows which contain word "Complete" in column D to the top of the table (insert in row 3). Is that possible? then I would like to delete all these complete rows which contain "yesterday date" in column V.
  • To post as a guest, your comment is unpublished.
    Anon · 1 years ago
    How could I make it so the kutools selects specific rows without user input?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Anon,
      I am sorry, I'm not sure what you mean. Would be nice if you can explain it again or provide a screenshot to show what you are trying to do .
      Thanks for your comment.