Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Macro for clearing cell contents

Hi there,

I have a 52 sheet workbook and I would like a macro to clear the contents of
cells starting at row 2 onwards for all 52 sheets. However, some columns
contain formulas which I would like to preserve.

Any ideas would be gratefully received.

Many thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Macro for clearing cell contents

Assuming identical structured sheets,
you could try something like this ..

Sub ClearContents()
Dim wkSht As Worksheet
For Each wkSht In Worksheets
wkSht.Range("A2:C3000,F2:G3000").ClearContents
'edit ranges to suit max row & cols to exclude (eg cols D,E in above)
Next wkSht
End Sub

--
Max
Singapore
http://savefile.com/projects/236895
Downloads:22,000 Files:370 Subscribers:66
xdemechanik
---
"Sal" wrote:
I have a 52 sheet workbook and I would like a macro to clear the contents of
cells starting at row 2 onwards for all 52 sheets. However, some columns
contain formulas which I would like to preserve.

Any ideas would be gratefully received.

Many thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Macro for clearing cell contents


The OP indicated wanting to keep the formulas intact, so this adjustment
would clear only numeric and text cells.
==========
Sub ClearContents()
Dim wkSht As Worksheet
For Each wkSht In Worksheets
wkSht.Range("A2:C3000,F2:G3000").SpecialCells(xlCe llTypeConstants,
xlNumbers + xlTextValues).ClearContents
'edit ranges to suit max row & cols to exclude (eg cols D,E in above)
Next wkSht
End Sub
==========


Max;175030 Wrote:
Assuming identical structured sheets,
you could try something like this ..

Sub ClearContents()
Dim wkSht As Worksheet
For Each wkSht In Worksheets
wkSht.Range("A2:C3000,F2:G3000").ClearContents
'edit ranges to suit max row & cols to exclude (eg cols D,E in above)
Next wkSht
End Sub

--
Max
Singapore
'Free file hosting by Savefile.com'
(http://savefile.com/projects/236895)
Downloads:22,000 Files:370 Subscribers:66
xdemechanik
---
"Sal" wrote:
I have a 52 sheet workbook and I would like a macro to clear the

contents of
cells starting at row 2 onwards for all 52 sheets. However, some

columns
contain formulas which I would like to preserve.

Any ideas would be gratefully received.

Many thanks



--
JBeaucaire
------------------------------------------------------------------------
JBeaucaire's Profile: http://www.thecodecage.com/forumz/member.php?userid=73
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=48382

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Macro for clearing cell contents

Hi Max,

Many thanks, this works really well as I have excluded the columns with
formulas in them. This will save me heaps of time.

"Max" wrote:

Assuming identical structured sheets,
you could try something like this ..

Sub ClearContents()
Dim wkSht As Worksheet
For Each wkSht In Worksheets
wkSht.Range("A2:C3000,F2:G3000").ClearContents
'edit ranges to suit max row & cols to exclude (eg cols D,E in above)
Next wkSht
End Sub

--
Max
Singapore
http://savefile.com/projects/236895
Downloads:22,000 Files:370 Subscribers:66
xdemechanik
---
"Sal" wrote:
I have a 52 sheet workbook and I would like a macro to clear the contents of
cells starting at row 2 onwards for all 52 sheets. However, some columns
contain formulas which I would like to preserve.

Any ideas would be gratefully received.

Many thanks

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Macro for clearing cell contents

Hi,

When I copy this code to test it I get a syntax error on the following:

wkSht.Range("A2:C3000,F2:G3000").SpecialCells(xlCe llTypeConstants,
xlNumbers + xlTextValues).ClearContents

Any ideas? The suggestion from Max worked for my purposes but it would be
useful to understand your code also.

Many thanks for your time.

"JBeaucaire" wrote:


The OP indicated wanting to keep the formulas intact, so this adjustment
would clear only numeric and text cells.
==========
Sub ClearContents()
Dim wkSht As Worksheet
For Each wkSht In Worksheets
wkSht.Range("A2:C3000,F2:G3000").SpecialCells(xlCe llTypeConstants,
xlNumbers + xlTextValues).ClearContents
'edit ranges to suit max row & cols to exclude (eg cols D,E in above)
Next wkSht
End Sub
==========


Max;175030 Wrote:
Assuming identical structured sheets,
you could try something like this ..

Sub ClearContents()
Dim wkSht As Worksheet
For Each wkSht In Worksheets
wkSht.Range("A2:C3000,F2:G3000").ClearContents
'edit ranges to suit max row & cols to exclude (eg cols D,E in above)
Next wkSht
End Sub

--
Max
Singapore
'Free file hosting by Savefile.com'
(http://savefile.com/projects/236895)
Downloads:22,000 Files:370 Subscribers:66
xdemechanik
---
"Sal" wrote:
I have a 52 sheet workbook and I would like a macro to clear the

contents of
cells starting at row 2 onwards for all 52 sheets. However, some

columns
contain formulas which I would like to preserve.

Any ideas would be gratefully received.

Many thanks



--
JBeaucaire
------------------------------------------------------------------------
JBeaucaire's Profile: http://www.thecodecage.com/forumz/member.php?userid=73
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=48382




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro for clearing cell contents

wkSht.Range("A2:C3000,F2:G3000").SpecialCells(xlC ellTypeConstants,
xlNumbers + xlTextValues).ClearContents


You got hit by line wrap on the line above.

Add a line-continuation mark(_) to have Excel treat it as one line.

wkSht.Range("A2:C3000,F2:G3000").SpecialCells(xlCe llTypeConstants, _
xlNumbers + xlTextValues).ClearContents


Gord Dibben MS Excel MVP


  #7   Report Post  
Posted to microsoft.public.excel.misc
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Macro for clearing cell contents

Glad it helped. Appreciate it you would sign-in as the original poster name
"Sal", then mark that earlier response by pressing the YES button (like the
one below).
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:22,000 Files:370 Subscribers:66
xdemechanik
---
"Mustang" wrote:
Hi Max,

Many thanks, this works really well as I have excluded the columns with
formulas in them. This will save me heaps of time.


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
Clearing Cell Contents / Worksheet_Change Event Grahame Coyle[_2_] Excel Worksheet Functions 5 September 5th 08 01:09 PM
Clearing contents not formatting JSnow Excel Discussion (Misc queries) 3 August 13th 08 04:26 PM
Selectively Clearing cell contents jdd Excel Worksheet Functions 2 April 22nd 06 04:06 AM
Clearing Contents of Cell Burt Excel Worksheet Functions 1 May 4th 05 02:46 PM
Clearing Contents but not Formulas Louise Excel Worksheet Functions 6 January 27th 05 05:04 PM


All times are GMT +1. The time now is 09:32 AM.

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"