Clear Contents

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
688
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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
 

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
688
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,683
Messages
5,637,787
Members
416,982
Latest member
lisam77

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
Top