+ Reply to Thread
Results 1 to 8 of 8

Clear contents - no formulas

  1. #1
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Clear contents - no formulas

    Hello,

    I have a macro for clearing contents after copying first sheet and creating new ones. VBA code is for clearing contents, but to leave all formulas within range intact.

    Code is :

    Please Login or Register  to view this content.
    Code works when there are actually some cells to clear, but If none (cells are clear - except formula cells) I receive error "no cells were found". How can I fix that, I want this code only to delete cells If user accidently types something in first sheet which is being copied.

    Tried this but not working :

    Please Login or Register  to view this content.
    Last edited by Lukael; 03-17-2014 at 11:56 AM.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Clear contents - no formulas

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Clear contents - no formulas

    thanks for response,

    but I still get error: "no cells found"

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Clear contents - no formulas

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Clear contents - no formulas

    Sorry, you are right, error handling like that doesn't work in a loop. Try this:
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Clear contents - no formulas

    AlphaFrog,

    your code works

    Thanks man, nicely done !

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Clear contents - no formulas

    Another option would be to use a "cheater" cell that will always maintain a constant by writing to it in code.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  8. #8
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Clear contents - no formulas

    Thanks Solus,

    I actually had that (on sheet - not VBA) but I rather prefer AlphaFrog's code, It's more correct.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Clear cell contents on closing/opening without clearing formulas
    By CFT Brian in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-28-2013, 03:47 PM
  2. [SOLVED] How do I clear contents from a range excluding formulas and text?
    By Normezo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-23-2012, 10:36 AM
  3. excel command to clear contents except 2 formulas
    By Lynda S in forum Excel General
    Replies: 6
    Last Post: 07-14-2006, 10:15 AM
  4. Clear contents but leave formulas in Excel
    By ojchippy in forum Excel - New Users/Basics
    Replies: 10
    Last Post: 06-16-2006, 11:15 PM
  5. [SOLVED] [SOLVED] Excel should let me clear cell contents without clearing formulas
    By BJM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-19-2005, 01:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1