How to move rows down to the bottom of my current worksheet once completed

robboe

New Member
Joined
Jan 13, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I am trying to figure out how to set up my worksheet so that all the rows where column G says "completed" move down to the bottom of the current spreadsheet and also have the entire row automatically highlight grey once it's listed as completed as well. I think i'm going to leave Column G as a free-form one and just have people type in completed instead of using a drop down. I have found a couple codes on here, but none of them seemed to be exactly what i was looking for. I'm also not too familiar with VBA so would need some help with the steps to actually add the code. Any help would be greatly appreciated. :)


1642082194962.png
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi and welcome to MrExcel.

Put the following code in the events of your sheet.

SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.

Go back to the sheet, change the status in column G.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rng As Range, c As Range, mvrng As Range
  Dim lr As Long

  Set rng = Intersect(Target, Range("G2:G" & Rows.Count))
  If Not rng Is Nothing Then
    For Each c In rng
      If LCase(c.Value) = LCase("completed") Then
        If mvrng Is Nothing Then Set mvrng = Range("A" & c.Row & ":I" & c.Row) Else Set mvrng = Union(mvrng, Range("A" & c.Row & ":I" & c.Row))
      End If
    Next
    If Not mvrng Is Nothing Then
      Application.EnableEvents = False
      mvrng.Interior.ColorIndex = 15
      mvrng.Copy Range("A" & Rows.Count).End(3)(2)
      mvrng.Delete Shift:=xlUp
      Application.EnableEvents = True
    End If
  End If
End Sub
 
Upvote 0
Solution
Hi and welcome to MrExcel.

Put the following code in the events of your sheet.

SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.

Go back to the sheet, change the status in column G.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rng As Range, c As Range, mvrng As Range
  Dim lr As Long

  Set rng = Intersect(Target, Range("G2:G" & Rows.Count))
  If Not rng Is Nothing Then
    For Each c In rng
      If LCase(c.Value) = LCase("completed") Then
        If mvrng Is Nothing Then Set mvrng = Range("A" & c.Row & ":I" & c.Row) Else Set mvrng = Union(mvrng, Range("A" & c.Row & ":I" & c.Row))
      End If
    Next
    If Not mvrng Is Nothing Then
      Application.EnableEvents = False
      mvrng.Interior.ColorIndex = 15
      mvrng.Copy Range("A" & Rows.Count).End(3)(2)
      mvrng.Delete Shift:=xlUp
      Application.EnableEvents = True
    End If
  End If
End Sub
That worked in the practice spreadsheet i was testing it on, but when I tried to get it to work in my spreadsheet at work, it's either moving the "completed" items to the top or they are disappearing and not just going to the bottom of the spreadsheet like they did in my test spreadsheet. Here is what the actual blank spreadsheet looks like- does something in the code need to be changed?
1642601432064.png
 
Upvote 0
That worked in the practice spreadsheet i was testing it on, but when I tried to get it to work in my spreadsheet at work, it's either moving the "completed" items to the top or they are disappearing and not just going to the bottom of the spreadsheet like they did in my test spreadsheet. Here is what the actual blank spreadsheet looks like- does something in the code need to be changed?
View attachment 55589
Nevermind - I think it was because i didnt have any data in the spreadsheet yet. Once I added items to the list it worked. thank you!
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top