Results 1 to 4 of 4

Thread: VBA code to delete cell ranges

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    78
    Rep Power
    13

    VBA code to delete cell ranges

    Hi

    I require a VBA code to delete the following cell ranges
    D3:N9
    D13:N19
    D23:N29
    D33:N39
    D43:N49
    D53:N59
    D63:N69
    all the way down to
    D273:N279
    Sheet name is Score

    Thanks

    Rich

  2. #2
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Code:
    Sub DeleteRanges()
        
        With Sheets("Score")
            For i = 3 To 273 Step 10
                .Range("D" & i).Resize(7, 11).ClearContents
            Next
        End With
        
    End Sub

  3. #3
    Member
    Join Date
    Dec 2012
    Posts
    78
    Rep Power
    13
    thanks

    Can you add a message box before deleting which says "are you sure you want to delete data"

    Thanks

    Rich

  4. #4
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    This really wasn't so hard, not ?

    Code:
    Sub DeleteRanges()
    
        If MsgBox("Are you sure you want to delete data ?", vbYesNoCancel + vbExclamation, "Delete data") = vbYes Then
            With Sheets("Score")
                For i = 3 To 273 Step 10
                    .Range("D" & i).Resize(7, 11).ClearContents
                Next
            End With
        End If
        
    End Sub

Similar Threads

  1. Replies: 14
    Last Post: 06-24-2013, 06:17 PM
  2. Removing unused Cell styles - need an efficient code
    By siddharthsindhwani in forum Excel Help
    Replies: 8
    Last Post: 04-15-2013, 07:12 AM
  3. VB code to Run formula untill blank cell
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 8
    Last Post: 05-20-2012, 11:08 AM
  4. Replies: 4
    Last Post: 05-14-2012, 11:58 AM
  5. Delete Name Ranges by Scope VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 12-20-2011, 03:54 AM

Posting Permissions

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