PC Review


Reply
Thread Tools Rate Thread

How to clear contents of multiple cells in Excel simultaneously

 
 
Jaclyn
Guest
Posts: n/a
 
      5th Jan 2010
I would like to allow users to clear the contents from all of the unprotected
cells in multiple sheets of a workbook, simultaneously.

I read a similar posting on the subject in
microsoft.public.excel.worksheet.functions, posted by sstea, titled How to
clear multiple cells of input data in Excel simultaneously. The suggested
code was as follows:

Sub ClearForm()
Dim c As Range
For Each c In Sheets("sheet1").UsedRange
If c.Locked = False Then
c.ClearContents
End If
Next

End Sub

This was a good start but I ran into errors.

1. Runtime error '1004'. Cannot change part of a merged cell. How do I
edit this code to clear the contents of unprotected merged cells?
2. How do I make this simultaneously work on multiple sheets in the workbook?

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      5th Jan 2010
Change:

c.ClearContents
to
c.Value = ""

And to get all the worksheets:

Sub ClearForm()
Dim c As Range
dim wks as worksheet
for each wks in activeworkbook.worksheets
For Each c In Sheets("sheet1").UsedRange.Cells
If c.Locked = False Then
c.value = ""
end if
next c
next wks

End Sub

Jaclyn wrote:
>
> I would like to allow users to clear the contents from all of the unprotected
> cells in multiple sheets of a workbook, simultaneously.
>
> I read a similar posting on the subject in
> microsoft.public.excel.worksheet.functions, posted by sstea, titled How to
> clear multiple cells of input data in Excel simultaneously. The suggested
> code was as follows:
>
> Sub ClearForm()
> Dim c As Range
> For Each c In Sheets("sheet1").UsedRange
> If c.Locked = False Then
> c.ClearContents
> End If
> Next
>
> End Sub
>
> This was a good start but I ran into errors.
>
> 1. Runtime error '1004'. Cannot change part of a merged cell. How do I
> edit this code to clear the contents of unprotected merged cells?
> 2. How do I make this simultaneously work on multiple sheets in the workbook?


--

Dave Peterson
 
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
Excel: Combine contents from identical cells on multiple sheets. Milan Microsoft Excel New Users 1 7th Mar 2010 01:50 PM
How to clear multiple cells of input data in Excel simultaneously =?Utf-8?B?c3N0ZWE=?= Microsoft Excel Worksheet Functions 12 2nd May 2009 08:47 PM
In Excel how do I update cells in multiple sheets simultaneously? kjh1210 Microsoft Excel Misc 1 22nd Apr 2009 11:01 PM
Excel 2000 - Split Contents of Cell Across Multiple Cells =?Utf-8?B?RGVlVw==?= Microsoft Excel Misc 7 8th Nov 2006 09:10 PM
clear contents cells of unprotected cells =?Utf-8?B?RWQ=?= Microsoft Excel Programming 6 12th Jan 2006 06:09 PM


Features
 

Advertising
 

Newsgroups
 


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