PC Review


Reply
Thread Tools Rate Thread

how to clear cells quick?

 
 
=?Utf-8?B?SmFyZWQ=?=
Guest
Posts: n/a
 
      7th Oct 2006
I have a macro which will clear a whole bunch of cells from a whole bunch of
sheets. It takes forever. I do not know if there is a better/faster way to do
this. One idea of mine is to select muliple cells and then clear the selected
cells instead of one by one.
There might be a better way. Any suggestions?

Sub Clear_The_Month()


' Clear_The_Month Macro
' Macro recorHeH 9/14/2006 by Rapture Marketing
'

'
Dim c As Integer
Dim r As Integer
Dim sr As Integer
Dim s As Integer
Dim lw As Integer



Application.ScreenUpdating = False

lw = 16
For s = 5 To 36
If s >= 31 Then lw = 9
If Sheets(s).Name <> "salaries" And Sheets(s).Name <> "salaries 2"
Then
For c = 4 To lw Step 2
For r = 2 To 74 Step 6
For sr = 1 To 4
If Not IsEmpty(Worksheets(s).Cells((sr + r), c))
Then Worksheets(s).Cells((sr + r), c).ClearContents
Next sr
Next r
Next c
For c = 4 To lw Step 2
For r = 83 To 87 Step 2
If Not IsEmpty(Worksheets(s).Cells(r, c)) Then
Worksheets(s).Cells(r, c).ClearContents
Next r
Next c
For c = 4 To lw Step 2
For r = 95 To 193 Step 2
If Not IsEmpty(Worksheets(s).Cells(r, c)) Then
Worksheets(s).Cells(r, c).ClearContents
Next r
Next c
End If
Next s

End Sub

Thanks
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sk5X?=
Guest
Posts: n/a
 
      11th Oct 2006
If the cells you want to clear are always the same you may consider using
Application.union

For example:
dim ClearRange as range
set ClearRange = application.union(range("A1"),range("F6"))
ClearRange.clearcontents
'continue setting ClearRange for each set of cells you want to clear.

You shouldn't have to test if the cell is empty since you are going to clear
it anyway.
--
JNW


"Jared" wrote:

> I have a macro which will clear a whole bunch of cells from a whole bunch of
> sheets. It takes forever. I do not know if there is a better/faster way to do
> this. One idea of mine is to select muliple cells and then clear the selected
> cells instead of one by one.
> There might be a better way. Any suggestions?
>
> Sub Clear_The_Month()
>
>
> ' Clear_The_Month Macro
> ' Macro recorHeH 9/14/2006 by Rapture Marketing
> '
>
> '
> Dim c As Integer
> Dim r As Integer
> Dim sr As Integer
> Dim s As Integer
> Dim lw As Integer
>
>
>
> Application.ScreenUpdating = False
>
> lw = 16
> For s = 5 To 36
> If s >= 31 Then lw = 9
> If Sheets(s).Name <> "salaries" And Sheets(s).Name <> "salaries 2"
> Then
> For c = 4 To lw Step 2
> For r = 2 To 74 Step 6
> For sr = 1 To 4
> If Not IsEmpty(Worksheets(s).Cells((sr + r), c))
> Then Worksheets(s).Cells((sr + r), c).ClearContents
> Next sr
> Next r
> Next c
> For c = 4 To lw Step 2
> For r = 83 To 87 Step 2
> If Not IsEmpty(Worksheets(s).Cells(r, c)) Then
> Worksheets(s).Cells(r, c).ClearContents
> Next r
> Next c
> For c = 4 To lw Step 2
> For r = 95 To 193 Step 2
> If Not IsEmpty(Worksheets(s).Cells(r, c)) Then
> Worksheets(s).Cells(r, c).ClearContents
> Next r
> Next c
> End If
> Next s
>
> End Sub
>
> Thanks

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup cells in one column and clear cells in another JoshW0000 Microsoft Excel Programming 5 3rd Sep 2009 03:01 PM
Add Clear Flag to Quick Access Toolbar Matt Greer Microsoft Outlook Discussion 6 25th Jan 2008 01:54 AM
Create a Clear button to clear unprotected cells Jcraig713 Microsoft Excel Programming 2 26th Nov 2007 03:55 PM
clear contents cells of unprotected cells =?Utf-8?B?RWQ=?= Microsoft Excel Programming 6 12th Jan 2006 06:09 PM
Clear cells range if certain cells are all empty gschimek - ExcelForums.com Microsoft Excel Programming 6 13th May 2005 10:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:29 PM.