Results 1 to 2 of 2

Thread: [RESOLVED] ClearContents error

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Resolved [RESOLVED] ClearContents error

    I did a search and did not see the same issue.

    I have Excel2013. Worksheet "Admin" contain the name of the spreadsheet to clear. I want to clear all of the cells on the destination worksheet.


    For rep = 1 To 15
    output_sheet_Current = Sheets("Admin").Range("D" & rep).Value
    Worksheets(output_sheet_Current).Range("A1:L50").ClearContents
    Next rep

    Output_sheet_current does contain the proper name of the sheet I want to clear. It appears to dislike the Range() clause.

    "Clear method of range class failed" error 1004.

    Any ideas?
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  2. #2

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: ClearContents error

    I got it to work. using this code:

    For rep = 1 To 15
    output_sheet_Current = Sheets("Admin").Range("D" & rep).Value
    If Worksheets(output_sheet_Current).UsedRange.Rows.Count > 0 Then
    Worksheets(output_sheet_Current).UsedRange.ClearContents
    End If
    Next rep

    Evidently, if no rows were used it would fail.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

Posting Permissions

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



Click Here to Expand Forum to Full Width