Salt la conținutul principal

Cum să mutați întregul rând în partea de jos a foii active pe baza valorii celulei din Excel?

Pentru a muta întregul rând în partea de jos a foii active pe baza valorii celulei din Excel, încercați codul VBA din acest articol.

Mutați întregul rând în partea de jos a foii active pe baza valorii celulei cu cod VBA


Mutați întregul rând în partea de jos a foii active pe baza valorii celulei cu cod VBA

De exemplu, după cum se arată în imaginea de mai jos, dacă o celulă din coloana C conține o anumită valoare „Terminat”, mutați întregul rând în partea de jos a foii curente. Vă rugăm să faceți următoarele.

1. presa Alt+ F11 tastele simultan pentru a deschide Microsoft Visual Basic pentru aplicații fereastră.

2. În Microsoft Visual Basic pentru aplicații fereastră, faceți clic pe Insera > Module. Apoi copiați și lipiți codul VBA de mai jos în fereastră.

Cod VBA: Mutați întregul rând în partea de jos a foii active pe baza valorii celulei

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

notițe: În codul VBA, „Terminat ”Este valoarea celulei pe care veți muta întregul rând pe baza căruia. Îl puteți schimba după cum aveți nevoie.

3. apasă pe F5 tasta pentru a rula codul, apoi în fereastra pop-up Kutools pentru Excel caseta de dialog, selectați intervalul de coloane în care există o anumită valoare, apoi faceți clic pe OK butonul.

După ce faceți clic OK butonul, întregul rând care conține valoarea „Terminat” în coloana specificată este mutat automat în partea de jos a intervalului de date.


Articole pe aceeași temă:

Cele mai bune instrumente de productivitate de birou

🤖 Kutools AI Aide: Revoluționați analiza datelor pe baza: Execuție inteligentă   |  Generați codul  |  Creați formule personalizate  |  Analizați datele și generați diagrame  |  Invocați funcțiile Kutools...
Caracteristici populare: Găsiți, evidențiați sau identificați duplicatele   |  Ștergeți rândurile goale   |  Combinați coloane sau celule fără a pierde date   |   Rundă fără Formula ...
Super căutare: VLookup cu mai multe criterii    VLookup cu valori multiple  |   VLookup pe mai multe foi   |   Căutare fuzzy ....
Listă derulantă avansată: Creați rapid o listă derulantă   |  Listă drop-down dependentă   |  Listă derulantă cu selectare multiplă ....
Manager de coloane: Adăugați un număr specific de coloane  |  Mutați coloanele  |  Comutați starea vizibilității coloanelor ascunse  |  Comparați intervale și coloane ...
Caracteristici prezentate: Focus pe grilă   |  Vedere de proiectare   |   Big Formula Bar    Manager registru de lucru și foi   |  Biblioteca de resurse (Text automat)   |  Data Picker   |  Combinați foi de lucru   |  Criptare/Decriptare celule    Trimiteți e-mailuri după listă   |  Super Filtru   |   Filtru special (filtrează bold/italic/barat...) ...
Top 15 seturi de instrumente12 Text Instrumente (Adăuga text, Eliminați caractere,...)   |   50+ Diagramă Tipuri de (Gantt Chart,...)   |   40+ Practic Formule (Calculați vârsta pe baza zilei de naștere,...)   |   19 inserare Instrumente (Introduceți codul QR, Inserați imaginea din cale,...)   |   12 Convertire Instrumente (Numere la cuvinte, conversie valutara,...)   |   7 Merge & Split Instrumente (Rânduri combinate avansate, Celule divizate,...)   |   ... și altele

Îmbunătățiți-vă abilitățile Excel cu Kutools pentru Excel și experimentați eficiența ca niciodată. Kutools pentru Excel oferă peste 300 de funcții avansate pentru a crește productivitatea și a economisi timp.  Faceți clic aici pentru a obține funcția de care aveți cea mai mare nevoie...

Descriere


Fila Office aduce interfața cu file în Office și vă face munca mult mai ușoară

  • Activați editarea și citirea cu file în Word, Excel, PowerPoint, Publisher, Access, Visio și Project.
  • Deschideți și creați mai multe documente în filele noi ale aceleiași ferestre, mai degrabă decât în ​​ferestrele noi.
  • Vă crește productivitatea cu 50% și reduce sute de clicuri de mouse pentru dvs. în fiecare zi!
Comments (30)
Rated 4.75 out of 5 · 2 ratings
This comment was minimized by the moderator on the site
How can you automatically move the rows in an online excel sheet?
This comment was minimized by the moderator on the site
Is there any way I can do this in an online excel sheet?
This comment was minimized by the moderator on the site
Is there a way to move rows back to the original place when the status of the input changes? For example if someone changes it from "Done" to "incomplete", is there a way to program excel to move it back?
Also, is this change permanent ? I've noticed after working the first time, it stopped working after that.

Thank you for your help and post!
Rated 4.5 out of 5
This comment was minimized by the moderator on the site
Hi zoe,

Thank you for your comment.
1. For the first question:
The row that was moved can't be moved back to its original place;
2. For the second question:
This VBA code needs to be run manually each time you need to move rows. If you want to move the row automatically when the cell value matches the condition, you can try the following VBA code.
Notes: You need to put this code in the Sheet (Code) editor (Right click the sheet tab and select View Code to open the editor). And change the column range B2:B12 to your own range.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updated Extendoffice 20230111
    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 = Range("B2:B12")
    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
This comment was minimized by the moderator on the site
Hi Crystal,

Thank you for all of the great codes. Is there a way to do this without the Kutools? I also don't see a dialog box to select a cell range, it isn't popping up for me.

Thank you,
Jaz
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi Jaz,
You can specify the cell range directly in the code without having to pop up the Kutools dialog box to select the range.
In the code, please replace the following line:
Set xRg = Application.InputBox("Select range:", "Kutools for Excel", xTxt, , , , , 8)

with:
Set xRg = Range("C2:C13")
This comment was minimized by the moderator on the site
me again! I figured the code out. I had manually copied and pasted the code rather than use the copy button on the top right of the screen. I changed "done" to "x". I have run the code in each of the worksheets. As I start entering in "x" in those cells within the selected cell ranges from the dialog box, nothing happens (rows do not automatically move down to the bottom). I am VERY NEW to this....thanks for your help!
This comment was minimized by the moderator on the site
Hi,
If you want to automatically move the row to bottom when entering the specified word, please try the following VBA code.
Note: you need to enter the code into the Worksheet code window (right click the sheet tab and select View Code from the context menu).

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updated by Extendoffice 20220520
    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 = Range("C2:C18")
    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
This comment was minimized by the moderator on the site
Hi! I just purchased kutools so that I could *** this vba code to my excel sheet, as it will be an excellent feature to use! The instructions above are simple and helpful; however, once I get to the step where the code is copied and pasted in the window and press F5, it sent me to a box to name and create the macro. I did that but now it won't take me to the dialog box so I can select cell range. A compile error of "invalid outside procedure" pops up. Please help!
This comment was minimized by the moderator on the site
Hi,
I'm sorry to have misled you. The code can be used on its own and does not require the purchase of Kutools. If you don't need it, please email to to ask for a refund.
For the code to work smoothly, you need to make sure that your cursor is in the code window (click on any word in the code), then press the F5 key to run the code. Then the dialog box to select a cell range will pop up.
Sorry again for the inconvenience.
This comment was minimized by the moderator on the site
I have a list with check boxes that when one column is checked I need it to go to one section of the spreadsheet and if the other is checked instead it goes to the end. I have tried a hundred diff ways to do this can anyone help with this?
This comment was minimized by the moderator on the site
Hi Crystal,
Thanks for you help, the code works great but rather than move the row to the bottom of a page how to I move it to another tab i.e. a "Closed" tab?
This comment was minimized by the moderator on the site
Hi,
Sorry for replying so late.
In the code, you just need to change the line "If xRg.Cells(I) = "Done" Then" to If xRg.Cells(I) Like "*Done*" Then to get it done.
This comment was minimized by the moderator on the site
How do it if "Done" is only a part of a column string. Suppose my Columns contains value like - XYZDone, ABCDone, 123Done etc, can I just filter out based on partial string "Done"?
This comment was minimized by the moderator on the site
Hello, I have a task my boss has given me. It seemed simple enough at first but now I am confused as how to proceed. We have a Forecast sheet of the possible jobs and they have a "Order Probability" column by %. He wants me to set up 3 different sheets with 100-70%, 69%-41, and 40-0%. The idea is that as the information is typed inot the master sheet, when the percentage is entered in, it automatically gets copied into the proceeding sheet matching that percentile rage. I did this with a simple IF(and formula. However i need to sort inorder to loose the empty cells and make it look cleaner. Then when i sort , if i add a new Oder Probability offer to the master sheet, it does not automatically show it, without unsorting then sorting again. I apologize if this question does not belong her. But is there a string of code i could put in that would handle this issue easier? The only value that determines if the whole row gets moved is the K column. seems simple, but however complex for this excel beginner. Thanks in advance for your help.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations