#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Cells.Clear


Hi,


Worksheets("Sheet1").Cells.Clear
will clear the sheet.

If there a way that we can clear Cells less defined range?

some thing like Cells excluding "MyRange" .clear? so that t will be so
fast and without using loop

thanks



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Cells.Clear

Try

Sheets("Sheet1").Range("A1:B20").ClearContents

Mike

On Mar 1, 6:44*am, Abdul wrote:
Hi,

Worksheets("Sheet1").Cells.Clear
will clear the sheet.

If there a way that we can clear Cells less defined range?

some thing like Cells excluding "MyRange" .clear? so that t will be so
fast and without using loop

thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cells.Clear

One way:

Option Explicit
Sub testme()
Dim TempWks As Worksheet
Dim AddrToClear As String
Dim CurWks As Worksheet
Dim myRng As Range

Set CurWks = Worksheets("Sheet1")

Set myRng = Nothing
On Error Resume Next
Set myRng = CurWks.Range("MyRange")
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "no range with that name on the sheet"
Exit Sub
End If

Application.ScreenUpdating = False

Set TempWks = Workbooks.Add(1).Worksheets(1)

With TempWks
.Range(CurWks.UsedRange.Address).Value = 1
.Range(myRng.Address).Clear
AddrToClear = ""
On Error Resume Next
AddrToClear = .Cells.SpecialCells(xlCellTypeConstants).Address
On Error GoTo 0
.Parent.Close savechanges:=False
End With

Application.ScreenUpdating = True

If AddrToClear = "" Then
MsgBox "nothing to clear"
Else
CurWks.Range(AddrToClear).Clear
End If

End Sub


Abdul wrote:

Hi,

Worksheets("Sheet1").Cells.Clear
will clear the sheet.

If there a way that we can clear Cells less defined range?

some thing like Cells excluding "MyRange" .clear? so that t will be so
fast and without using loop

thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Cells.Clear

Or another way:
Sub test()
Dim MyRng As Range

Set MyRng = Application.InputBox(Prompt:="Select the range you wish to
keep", _
Title:="Keep Range", Type:=8)
Application.DisplayAlerts = False
Application.ScreenUpdating = False
MyRng.Copy
Sheets.Add.Name = "Temp"
Sheets("Temp").Range("A1").PasteSpecial (xlPasteAll)
Sheets("Sheet1").Cells.ClearContents
Sheets("Temp").UsedRange.Copy
Sheets("Sheet1").Activate
MyRng.PasteSpecial (xlPasteAll)
Sheets("Temp").Delete
Range("A1").Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


Mike F
"Abdul" wrote in message
...

Hi,


Worksheets("Sheet1").Cells.Clear
will clear the sheet.

If there a way that we can clear Cells less defined range?

some thing like Cells excluding "MyRange" .clear? so that t will be so
fast and without using loop

thanks





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a Clear button to clear unprotected cells Jcraig713 Excel Programming 2 November 26th 07 03:55 PM
Cells.Clear Ben Dummar Excel Discussion (Misc queries) 3 January 24th 07 10:50 PM
Clear cells One-Leg Excel Programming 3 June 3rd 06 12:20 AM
clear contents cells of unprotected cells Ed Excel Programming 6 January 12th 06 06:09 PM
Clear cells range if certain cells are all empty gschimek - ExcelForums.com Excel Programming 6 May 13th 05 10:38 PM


All times are GMT +1. The time now is 08:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"