Results 1 to 4 of 4

Need Help With VBA code Run-Time error 91

Threaded View

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    Tennessee
    MS-Off Ver
    Excel 2007
    Posts
    2

    Need Help With VBA code Run-Time error 91

    I am very new to VBA coding on Excel, and I have run into a problem, that I'm not sure what I've done wrong.

    I have a button designed on a worksheet to clear all the unprotected cells. This is the code:

    Sub ClearUnlockedCells()
        Dim WorkRange As Range
        Dim Cell As Range
        Dim intresponse As Integer
        Set WorkRange = ActiveSheet.UsedRange
        For Each Cell In WorkRange
        Next
        
        intresponse = MsgBox("Are you sure you want to Clear this Worksheet?", vbYesNo + vbQuestion, "Quit")
    
    If intresponse = vbNo Then End
    
    If intresponse = vbYes Then
           If Cell.Locked = False Then Cell.ClearContents
           
    End If
    
    End Sub
    When I try to run this, I get Run-Time Error 91, and the debugging points me back to the "If Cell.Locked = False" part.

    Any suggestions would be greatly appreciated.
    Last edited by jeffreybrown; 10-25-2012 at 11:54 AM. Reason: Please use code tags...Thanks.

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