+ Reply to Thread
Results 1 to 4 of 4

Deleting information macro

Hybrid View

  1. #1
    Registered User
    Join Date
    03-29-2007
    Posts
    20

    Deleting information macro

    i was wondering if anyone knows how i can have a macro to delete all information in a workbook (only unlocked cells) and have a warning box pop up with a delete confermation before the delete is completed and you can stop the delete if the button was hit by mistake thanks...

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon Scott McDermott

    How about something like this :

    Sub Macro1()
    response = MsgBox("Continue", vbYesNo, "Alert!")
    If response = vbYes Then
    ActiveSheet.UsedRange.Select
    For Each rng In Selection
    If rng.Locked = False Then
    rng.Clear
    End If
    Next rng
    End If
    End Sub
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    03-29-2007
    Posts
    20
    Thanks, that nearly works great i have mutipal sheats in the workbook that i need to clear at once, and the macro you tried total clears the cell gits rid of the color format and the boarders.. anything a little less agressive and will hit all the sheets at once? thanks

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi Scott McDermott

    Thanks, that nearly works great i have mutipal sheats in the workbook that i need to clear at once, and the macro you tried total clears the cell gits rid of the color format and the boarders.. anything a little less agressive and will hit all the sheets at once? thanks
    Hey! That's moving the goalposts

    Try this :

    Sub Macro1()
    response = MsgBox("Continue", vbYesNo, "Alert!")
    If response = vbYes Then
    Application.ScreenUpdating = False
    For Each AllSheet In ActiveWorkbook.Worksheets
    Sheets(AllSheet.Name).Activate
    ActiveSheet.UsedRange.Select
    For Each rng In Selection
    If rng.Locked = False Then
    rng.ClearContents
    End If
    Next rng
    Next AllSheet
    End If
    Application.ScreenUpdating = True
    End Sub
    HTH

    DominicB

+ 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