+ Reply to Thread
Results 1 to 9 of 9

Range.clear does not work

  1. #1
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Range.clear does not work

    I want to clear a range of cells in more worksheets. If I use e.g.

    Activesheet.Range(Cells(8,2),Cells(9,3)).clear

    it works fine. But when I use a different worksheet like eg.

    Sheets("FirstSheet").Range(Cells(8,2),Cells(9,3)).clear

    I get the error message: Error 1004 "Application-defined or Object-defined error"

    What to do?

    With kind regards

    Jan Lichtenbelt

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Range.clear does not work

    The syntax is correct. The error might be somewhere else in the code.

  3. #3
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Range.clear does not work

    I have the same problem if I program it just as one line in the Direct Window (Ctrl+G). That means it can not be due to other codes.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Range.clear does not work

    I do not see an error. Do you have merged cells?

  5. #5
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: Range.clear does not work

    I guess you have that macro in your personal Macro Book or in a workbook other than the one where the FirstSheet is in so make it

    Activeworkbook.Sheets("FirstSheet").Range(Cells(8,2),Cells(9,3)).clear

    Also make Sure that you have the name of the Sheet written correctly the error seems to be cause the sheet can not be found.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Range.clear does not work

    Hi,

    You haven't specified the sheet for the Cells:

    Please Login or Register  to view this content.
    You can also use a With block or a variable to make the code neater.

  7. #7
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Range.clear does not work

    Ok, the last one works correctly.

    Thanks a lot!

    Jan Lichtenbelt

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Range.clear does not work

    Or

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Range.clear does not work

    Make sure the sheet/s are not protected.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

+ 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 range upon Changing data in difference Range
    By snuffnchess in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2016, 02:22 AM
  2. [SOLVED] If each cell in range equals 0 then clear contents of range and move to the next row
    By dagardner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-19-2014, 08:44 PM
  3. VBA to clear and close work sheet when start new batch is clicked
    By superchew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2013, 11:50 PM
  4. Clear range based on cell value - clearing cells out of specified range
    By CADiphile in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-15-2013, 02:48 PM
  5. Replies: 1
    Last Post: 06-21-2013, 04:05 AM
  6. Clear diagrams does not work
    By whohe in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-14-2011, 08:09 AM
  7. [SOLVED] Clear Contents won't work on merged cells
    By ArthurJ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2006, 01:25 PM

Tags for this Thread

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