+ Reply to Thread
Results 1 to 4 of 4

ClearContents question

Hybrid View

  1. #1
    Forum Contributor Gabor's Avatar
    Join Date
    02-15-2004
    Location
    Székesfehérvár, Hungary
    MS-Off Ver
    xl2016
    Posts
    226

    ClearContents question

    This one works, but I don't like it:

    Sheets(1).Activate
    Worksheets(1).Range(Cells(2, 1), Cells(8888, 19)).Select
    Selection.ClearContents
    Range("A1").Select
    Sheets(2).Activate
    Worksheets(2).Range(Cells(2, 1), Cells(8888, 19)).Select
    Selection.ClearContents
    Range("A1").Select
    This one doesn't:
    With Worksheets(1)
        .Range(Cells(2, 1), Cells(8888, 19)).ClearContents
    End With
    
    With Worksheets(2)
        .Range(Cells(2, 1), Cells(8888, 19)).ClearContents
    End With
    Just need some streamlining, a good solution.
    Regards,

    Gabor

    Protect trees.. maybe one day we need to climb back....

  2. #2
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    464

    Re: ClearContents question

    does this not work?

    Worksheets(1).Range(Cells(2, 1), Cells(8888, 19)).ClearContents
    Worksheets(2).Range(Cells(2, 1), Cells(8888, 19)).ClearContents

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: ClearContents question

    Sheets(1).Range("A2:S8888").ClearContents
    Sheets(2).Range("A2:S8888").ClearContents
    or
    [Sheet1!A2:S8888].clearcontents
    [Sheet2!A2:S8888].clearcontents
    or
    sheets("sheet1").cells(2,1).resize(8887,19).clearcontents
    sheets("sheet2").cells(2,1).resize(8887,19).clearcontents
    Last edited by snb; 05-04-2011 at 05:45 AM.



  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: ClearContents question

    Gabor, I pointed out in your ealier post about referencing the actual sheets properly
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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