VBA to Move row to bottom in table depending on cell value

SarahMS1

New Member
Joined
Jan 29, 2020
Messages
20
Office Version
  1. 2016
Platform
  1. Windows
hello i’m new at work and i need help with a very easy task but i dont know how to do it with tables just with ranges in VBA, but its important to keep it as a table to my boss, what i need is a row goes to the bottom depending on the cell value on column O when it says “ DONE” and i prefer not with modules cause i dont want to run macro each time vba on the sheet code
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi and welcome to MrExcel!
some details.
Do you have formulas in the table?
Do you have empty rows in the table?
What is the name of the table?
What is the name of the field in column O?
 
Upvote 0
no formulas, no empty row but every-time we get a new status we inserting row so its an active sheet everyday it expands and the status of the row changes, the name is table2 the column name is Status
 
Upvote 0
Hi and welcome to MrExcel!
some details.
Do you have formulas in the table?
Do you have empty rows in the table?
What is the name of the table?
What is the name of the field in column O?

no formulas, no empty row but every-time we get a new status we inserting row so its an active sheet everyday it expands and the status of the row changes, the name is table2 the column name is Status
 
Upvote 0
Put the following code in the events of your sheet.

Each time write the word "DONE" in the status column of the "Table2" table, the row will move to the end of the table.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim tbl As ListObject, wRow As Long
  Set tbl = ActiveSheet.ListObjects("Table2")
  If Target.CountLarge > 1 Then Exit Sub
  If Not Intersect(Target, tbl.ListColumns("Status").Range) Is Nothing Then
    If UCase(Target.Value) = "DONE" Then
      Application.ScreenUpdating = False
      wRow = Target.Row - tbl.HeaderRowRange.Row
      tbl.ListRows.Add AlwaysInsert:=True
      tbl.DataBodyRange.Rows(wRow).Copy tbl.DataBodyRange.Rows(tbl.ListRows.Count)
      tbl.ListRows(wRow).Delete
    End If
  End If
End Sub
 
Upvote 0
t
Put the following code in the events of your sheet.

Each time write the word "DONE" in the status column of the "Table2" table, the row will move to the end of the table.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim tbl As ListObject, wRow As Long
  Set tbl = ActiveSheet.ListObjects("Table2")
  If Target.CountLarge > 1 Then Exit Sub
  If Not Intersect(Target, tbl.ListColumns("Status").Range) Is Nothing Then
    If UCase(Target.Value) = "DONE" Then
      Application.ScreenUpdating = False
      wRow = Target.Row - tbl.HeaderRowRange.Row
      tbl.ListRows.Add AlwaysInsert:=True
      tbl.DataBodyRange.Rows(wRow).Copy tbl.DataBodyRange.Rows(tbl.ListRows.Count)
      tbl.ListRows(wRow).Delete
    End If
  End If
End Sub
THANK YOU it worked!!!! ur a lifesaver!
 
Upvote 0
Put the following code in the events of your sheet.

Each time write the word "DONE" in the status column of the "Table2" table, the row will move to the end of the table.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim tbl As ListObject, wRow As Long
  Set tbl = ActiveSheet.ListObjects("Table2")
  If Target.CountLarge > 1 Then Exit Sub
  If Not Intersect(Target, tbl.ListColumns("Status").Range) Is Nothing Then
    If UCase(Target.Value) = "DONE" Then
      Application.ScreenUpdating = False
      wRow = Target.Row - tbl.HeaderRowRange.Row
      tbl.ListRows.Add AlwaysInsert:=True
      tbl.DataBodyRange.Rows(wRow).Copy tbl.DataBodyRange.Rows(tbl.ListRows.Count)
      tbl.ListRows(wRow).Delete
    End If
  End If
End Sub
Hello, I have a same situation.
Bur this code does not work on mine. Can you help me, please
Thank you in advance
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,456
Members
452,514
Latest member
cjkelly15

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