JARichard74
Board Regular
- Joined
- Dec 16, 2019
- Messages
- 114
- Office Version
- 365
- Platform
- Windows
I use this code to delete the number of rows based on a cell value.
ElseIf ThisWorkbook.Worksheets("Prep").ListObjects("Bidders").ListRows.Count > ThisWorkbook.Worksheets("Prep").Range("G1").Value Then
Set tbl = ThisWorkbook.Worksheets("Prep").ListObjects("Bidders")
lastrow = tbl.ListRows.Count
For x = lastrow To ThisWorkbook.Worksheets("Prep").Range("G1").Value Step -1
Set lr = tbl.ListRows(x)
lr.Delete
Next x
In this example I am going from a table with with 4 rows (excluding header row) Image1 to a table with two rows (excluding header row) Image2. The delete part works OK except that it also deleted content in the preceding row. I just want to delete the rows and keep content of remaining rows. Thanks for the help
ElseIf ThisWorkbook.Worksheets("Prep").ListObjects("Bidders").ListRows.Count > ThisWorkbook.Worksheets("Prep").Range("G1").Value Then
Set tbl = ThisWorkbook.Worksheets("Prep").ListObjects("Bidders")
lastrow = tbl.ListRows.Count
For x = lastrow To ThisWorkbook.Worksheets("Prep").Range("G1").Value Step -1
Set lr = tbl.ListRows(x)
lr.Delete
Next x
In this example I am going from a table with with 4 rows (excluding header row) Image1 to a table with two rows (excluding header row) Image2. The delete part works OK except that it also deleted content in the preceding row. I just want to delete the rows and keep content of remaining rows. Thanks for the help