Delete row values and columns after last row but exclude column A

KDS14589

Board Regular
Joined
Jan 10, 2019
Messages
182
Office Version
  1. 2016
Platform
  1. Windows
I wish to clear or delete rows in every column EXCEPT column 'A' based on the 'last row' in column 'B' starting in row '4'. For example, if I have a value in B10, then all rows below and to the right would be cleared or deleted but in values in column 'A' would not be harmed. i also posted this at Delete rows but not specific column

I've tried several solutions, but they all have 'ENTIREROW.DELETE'
DELETE.png
 

Attachments

  • DELETE.png
    DELETE.png
    48.9 KB · Views: 4

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Is this what you need ???
VBA Code:
Sub MM1()
Dim r As Long
For r = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(r, 2) = "" Then Range(Cells(r, 2), Cells(r, 6)).Clear
Next r
End Sub
 
Upvote 0
What about this?
(Test with a copy of your data)

VBA Code:
Sub Clear_Data()
  Range(Cells(Rows.Count, "B").End(xlUp).Offset(1), Cells.SpecialCells(xlCellTypeLastCell)).Clear
End Sub
 
Upvote 0
Is this what you need ???
VBA Code:
Sub MM1()
Dim r As Long
For r = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(r, 2) = "" Then Range(Cells(r, 2), Cells(r, 6)).Clear
Next r
End Sub
sorry went with a another. yours made an error, don't know why. THANKS for the effort.
 
Upvote 0
What about this?
(Test with a copy of your data)

VBA Code:
Sub Clear_Data()
  Range(Cells(Rows.Count, "B").End(xlUp).Offset(1), Cells.SpecialCells(xlCellTypeLastCell)).Clear
End Sub
IT WORKS . Thanks for code and effort
 
Upvote 0
IT WORKS . Thanks for code and effort
You're welcome. Thanks for the follow-up. :)

It may not occur with your worksheets but it is possible that under a certain circumstance my code could actually delete some data in the row where the last value in column B is.
To avoid that remote possibility, this would be safer code to rely on.

Rich (BB code):
Sub Clear_Data()
  Range(Cells(Rows.Count, "B").End(xlUp).Offset(1), Cells.SpecialCells(xlCellTypeLastCell).Offset(1)).Clear
End Sub
 
Last edited:
Upvote 0
Solution
You're welcome. Thanks for the follow-up. :)

It may not occur with your worksheets but it is possible that under a certain circumstance my code could actually delete some data in the row where the last value in column B is.
To avoid that remote possibility, this would be safer code to rely on.

Rich (BB code):
Sub Clear_Data()
  Range(Cells(Rows.Count, "B").End(xlUp).Offset(1), Cells.SpecialCells(xlCellTypeLastCell).Offset(1)).Clear
End Sub
Added it. Everything works fine. THANKS for the update and concern. Again Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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