PC Review


Reply
Thread Tools Rate Thread

Clear Spreadsheet Field

 
 
Glenn
Guest
Posts: n/a
 
      13th Oct 2009
Hi,

I would like a bit of VB code that when clicked will clear all unprotected
fields within a workbook.

Many thanks, Glenn
 
Reply With Quote
 
 
 
 
Sam Wilson
Guest
Posts: n/a
 
      13th Oct 2009
Sub demo()

Dim r As Range
Dim rng As Range
Dim c As Range

Dim ws As Worksheet

Set ws = ActiveSheet
Set r = ws.Cells.SpecialCells(xlCellTypeLastCell)
Set rng = Range(ws.Range("A1"), r)

For Each c In rng.Cells
If c.Locked = False Then c.ClearContents
Next c

End Sub

"Glenn" wrote:

> Hi,
>
> I would like a bit of VB code that when clicked will clear all unprotected
> fields within a workbook.
>
> Many thanks, Glenn

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      13th Oct 2009
Try

Sub Macro2()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If Not cell.Locked Then cell.ClearContents
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Glenn" wrote:

> Hi,
>
> I would like a bit of VB code that when clicked will clear all unprotected
> fields within a workbook.
>
> Many thanks, Glenn

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      13th Oct 2009
You said Workbook ?

Sub Macro2()
Dim cell As Range, ws As Worksheet
For Each ws In Worksheets
For Each cell In ws.UsedRange
If Not cell.Locked Then cell.ClearContents
Next
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

> Try
>
> Sub Macro2()
> Dim cell As Range
> For Each cell In ActiveSheet.UsedRange
> If Not cell.Locked Then cell.ClearContents
> Next
> End Sub
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Glenn" wrote:
>
> > Hi,
> >
> > I would like a bit of VB code that when clicked will clear all unprotected
> > fields within a workbook.
> >
> > Many thanks, Glenn

 
Reply With Quote
 
Sam Wilson
Guest
Posts: n/a
 
      13th Oct 2009
Or

Sub Macro2()
Dim cell As Range
dim ws as worksheet
for each ws in activeworkbook.worksheets
For Each cell In ws.UsedRange
If Not cell.Locked Then cell.ClearContents
Next cell
next ws

End Sub


"Jacob Skaria" wrote:

> Try
>
> Sub Macro2()
> Dim cell As Range
> For Each cell In ActiveSheet.UsedRange
> If Not cell.Locked Then cell.ClearContents
> Next
> End Sub
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Glenn" wrote:
>
> > Hi,
> >
> > I would like a bit of VB code that when clicked will clear all unprotected
> > fields within a workbook.
> >
> > Many thanks, Glenn

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      13th Oct 2009
You could give this routine a try; it will clear all unlocked cells on all
worksheets in the active workbook (and it should be pretty fast)...

Sub ClearUnlockedCells()
Dim C As Range, FoundCells As Range, SheetName As String
Dim WS As Worksheet, FirstAddress As String
Application.ScreenUpdating = False
Application.FindFormat.Locked = False
SheetName = ActiveSheet.Name
For Each WS In Worksheets
WS.Activate
Set FoundCells = Nothing
With WS.UsedRange
Set C = .Find("", SearchFormat:=True)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
If FoundCells Is Nothing Then
Set FoundCells = C
Else
Set FoundCells = Union(FoundCells, C)
End If
Set C = .Find("", after:=C, SearchFormat:=True)
Loop While Not C Is Nothing And C.Address <> FirstAddress
End If
If Not FoundCells Is Nothing Then FoundCells.Clear
End With
Next
Application.FindFormat.Clear
Worksheets(SheetName).Activate
Application.ScreenUpdating = True
End Sub

--
Rick (MVP - Excel)



"Glenn" <(E-Mail Removed)> wrote in message
news:7DE9BDFF-02B5-4359-BF7A-(E-Mail Removed)...
> Hi,
>
> I would like a bit of VB code that when clicked will clear all unprotected
> fields within a workbook.
>
> Many thanks, Glenn


 
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
how to sort (by one field), copy (based on one field) to another tab,then clear data on original sheet. Mel Microsoft Excel Programming 3 17th Apr 2009 09:18 PM
to clear contents of a spreadsheet =?Utf-8?B?SmVycnk=?= Microsoft Excel Misc 2 17th Aug 2007 02:20 AM
RE: to clear contents of a spreadsheet =?Utf-8?B?SmVycnk=?= Microsoft Excel Misc 0 17th Aug 2007 01:43 AM
Using control to clear spreadsheet =?Utf-8?B?ZHZvbmo=?= Microsoft Excel Misc 13 20th Mar 2006 10:29 AM
Clear All Information from Spreadsheet Sue Microsoft Excel Worksheet Functions 2 27th Sep 2004 10:43 PM


Features
 

Advertising
 

Newsgroups
 


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