Clear Contents

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
I have 2 values lngLastRow and lngLastColumn, and what I would like to do is clear the cell contents from C2 the corresponding cell for lngLastcolumn lngLastRow.

Any idea how to do this

Code:
lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
lngLastColumn = Sheets("Sheet1").Cells("1", Columns.Count).End(xlToLeft).Column

so if lngLastRow = 5 and lngLastColoumn = 4 I'd like to ClearContents for Range("C2:E5")
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try:

Code:
Sub Test()
    Dim lngLastRow As Long
    Dim lngLastColumn As Long
    lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
    lngLastColumn = Sheets("Sheet1").Cells("1", Columns.Count).End(xlToLeft).Column
    Range(Range("C2"), Cells(lngLastRow, lngLastColumn)).ClearContents
End Sub
 
Upvote 0
Ah that's how to do it, thanks Andrew.


The only way I could think to do it was to create another variable with the value Cells(lngLastRow,lngLastColomn).address
 
Upvote 0

Forum statistics

Threads
1,213,563
Messages
6,114,329
Members
448,564
Latest member
ED38

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