ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Clearing cell contents (https://www.excelbanter.com/excel-programming/360533-clearing-cell-contents.html)

Gina

Clearing cell contents
 
Hi,

I have the following bit of vba which works fine:

Worksheets("sheet1").Columns("A:E").ClearContents

What I would like to do is have it so that it doesn't delete the contents in
the first row. I know I could clear the contents using rows in the bit of
code instead of columns but there could potentially be hundreds of rows of
data so I wouldn't be able to specify a range.

Is there are way of deleting the contents from columns but exclude a
specific row?

Thanks

Norman Jones

Clearing cell contents
 
Hi Gina,

Try something like:

'=============
Public Sub Tester()
Dim rng As Range

With ActiveSheet
Set rng = Intersect(.UsedRange, .Columns("A:E"))
End With

Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)

rng.ClearContents
End Sub
'<<=============


---
Regards,
Norman



"Gina" wrote in message
...
Hi,

I have the following bit of vba which works fine:

Worksheets("sheet1").Columns("A:E").ClearContents

What I would like to do is have it so that it doesn't delete the contents
in
the first row. I know I could clear the contents using rows in the bit of
code instead of columns but there could potentially be hundreds of rows of
data so I wouldn't be able to specify a range.

Is there are way of deleting the contents from columns but exclude a
specific row?

Thanks




Gina

Clearing cell contents
 
Thanks, that worked perfectly.


"Norman Jones" wrote:

Hi Gina,

Try something like:

'=============
Public Sub Tester()
Dim rng As Range

With ActiveSheet
Set rng = Intersect(.UsedRange, .Columns("A:E"))
End With

Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)

rng.ClearContents
End Sub
'<<=============


---
Regards,
Norman



"Gina" wrote in message
...
Hi,

I have the following bit of vba which works fine:

Worksheets("sheet1").Columns("A:E").ClearContents

What I would like to do is have it so that it doesn't delete the contents
in
the first row. I know I could clear the contents using rows in the bit of
code instead of columns but there could potentially be hundreds of rows of
data so I wouldn't be able to specify a range.

Is there are way of deleting the contents from columns but exclude a
specific row?

Thanks






All times are GMT +1. The time now is 04:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com