Hi all,
How do I clear all cells in activesheet except first row by macro?
Thanks.
Hi all,
How do I clear all cells in activesheet except first row by macro?
Thanks.
Originally Posted by sheeeng
Dim rng Set rng = ActiveSheet.UsedRange Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1) rng.ClearContents
Can you explain more bout below code? I don't understand offset. Thanks.
rng.Offset(1, 0)
If I want to dim range as something, is it should be dim rng as range?
Dim rng
What isUsedRange
Thanks
It just takes the range offset by 1 row, that its bypasses row 1.Originally Posted by sheeeng
absolutelyOriginally Posted by sheeeng
Dim rng As Range
I had error here. This is because I put in userform terminate.
So even the sheet is empty except 1st row, it runs. How to have alternative to check whether need to clear sheet?
In Debug, rng.Rows.Count = 0Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
Solution here.
What is used range?If (rng.Rows.Count > 1) Then Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1) End If
Thanks.
The range of cells that have been used, a subset of the cells within the worksheet.Originally Posted by sheeeng
Thanks. Can we display the value of UsedRange?
No, it is an object. You can display its addressOriginally Posted by sheeeng
MsgBox Activesheet.UsedRange.Address
Thanks. Another solved.