Clear Cells in Last Row

Chris Lowe

New Member
Joined
Mar 25, 2015
Messages
28
I have a table where sometimes I need to delete everything in the last row, the table has columns from B to CP1.

I have managed to find the last row with vba but have so far only been able to select the cells one column at a time, is there a way that I can select the entire row of cells with data?
I used this code to select one at a time.

Code:
Range("B" & Rows.Count).End(xlUp).Select

I'm still very much learning all this stuff.
 
maybe...
Code:
Sub MM1()
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
With Rows(lr)
    .MergeCells = False
    .ClearContents
End With
End Sub
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I have cells merged both horizontally & vertically, for example B27:E28 is a block of merged cells.

Based on what you have said I may go back & start again without the merged cells.
 
Upvote 0
I have cells merged both horizontally & vertically, for example B27:E28 is a block of merged cells.

Based on what you have said I may go back & start again without the merged cells.
I think you better... the problem with vertically merged cells, especially if all columns are not merged for the same number of rows, is determining what the last "row" is.
 
Upvote 0
did you try my code ?
Also, why are the cells merged...?
you can achieve the same thing with
higlight the cells>>right click>>format>>alignment>>horizontal>>center across selection>
 
Upvote 0
Try this:
Code:
Sub ClearLastRow()
Rows(ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row).ClearContents
End Sub
 
Upvote 0
you can achieve the same thing with
higlight the cells>>right click>>format>>alignment>>horizontal>>center across selection>
I don't think you can do that with multiple rows in the selection (only the first selected row would be used).
 
Upvote 0
true...I was working on horizontal cells...not multiple rows.
Either way, I think you comment in Post #13 to be most relative.
 
Upvote 0
@my aswer is this.
Still wont do the desired effect with Merged cells
 
Upvote 0
Rick, I could not get your solution to work. Your solution looks for the last row in column 'B" what if column "G" is longer
I don't think you can do that with multiple rows in the selection (only the first selected row would be used).
 
Upvote 0
Rick, I could not get your solution to work. Your solution looks for the last row in column 'B" what if column "G" is longer
I used Column B because the OP did so in Message #1. A more generic LastRow finder for a given set of columns would be...
Code:
LastRow = Columns("B:CP").Find("*", , xlValues, , xlRows, xlPrevious).Row
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,048
Members
449,206
Latest member
Healthydogs

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