Code to delete row.

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,280
Office Version
  1. 2013
Platform
  1. Windows
Good Day,
Is it possible to delete the row between (A:AZ) of the last entry of worksheet datas with a code?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Do you mean if the last row of data is found in xxx you'd like code that deletes range Axxx:AZxxx only? Try:
Code:
Sub DelLast()

cells(cells(rows.count, 1).end(xlup).row ,1).Resize(,52).delete Shift:=xlup

End Sub
 
Upvote 0
Play SUBSTITUTE(@Fluff's comment, "en2", " ") by Michael Jackson (which just came on the radio!)
 
Last edited:
Upvote 0
Do you mean if the last row of data is found in xxx you'd like code that deletes range Axxx:AZxxx only? Try:
Code:
Sub DelLast()

cells(cells(rows.count, 1).end(xlup).row ,1).Resize(,52).delete Shift:=xlup

End Sub
You do not need the double Cells call as one would be enough...

Cells(Rows.Count, "A").End(xlUp).Resize(, 52).Delete xlUp
 
Upvote 0
Do you mean if the last row of data is found in xxx you'd like code that deletes range Axxx:AZxxx only? Try:
Code:
Sub DelLast()

cells(cells(rows.count, 1).end(xlup).row ,1).Resize(,52).delete Shift:=xlup

End Sub
You do not need the double Cells call as one would be enough...

Cells(Rows.Count, "A").End(xlUp).Resize(, 52).Delete xlUp
Of course, both of our code lines assume that Column A contains data in its cell on the last row that contains any data; however, if that might not be the case (for example, if the cell in Column A could be blank for the last row with data in it), then one of the two following more general code lines could be used, either this one...
Code:
[table="width: 500"]
[tr]
	[td]Columns("A:AZ").Find("*", , xlValues, , xlRows, xlPrevious, , , False).EntireRow.Columns(1).Resize(, 52).Delete xlUp[/td]
[/tr]
[/table]
or this one...
Code:
[table="width: 500"]
[tr]
	[td]Intersect(Columns("A:AZ").Find("*", , xlValues, , xlRows, xlPrevious, , , False).EntireRow, Columns("A:AZ")).Delete xlUp[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Code:
Columns("A:AZ").Find("*", , xlValues, , xlRows, xlPrevious, , , False).EntireRow.Columns(1).Resize(, 52).Delete xlUp

Rick,
Thanks a lot.
 
Upvote 0
@Rick Rothstein
You do not need the double Cells call as one would be enough...

Thank you Rick, I originally had Dim x as Long: x = cells(rows.count, 1).End(xlup).Row : Cells(x, 1) and then decided to get rid of x so text copy and replace created the double Cells!

Currently using a Mac which I do not like for VBA, so (likely with typos and mistakes like the one you spotted!) trying to type code directly in here or a standard text editor, and wasn't paying attention as tried to reduce number of code lines, thanks though!
 
Upvote 0

Forum statistics

Threads
1,215,140
Messages
6,123,266
Members
449,093
Latest member
Vincent Khandagale

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