+ Reply to Thread
Results 1 to 3 of 3

Help on writing a Macro to delete rows with certain criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    03-05-2011
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    27

    Help on writing a Macro to delete rows with certain criteria

    Hello,

    I am new to using Macros in excel (2003) and I am having problems writing a code to do the following.

    I have a spreadsheet with 100 rows. I would like to add a button to the spreadsheet to delete all completed rows based on the "Yes or No" response in the cell. Anytime there is a Yes in column K, I would like the button to delete the rows and shift the information up. I have a formula in column B that auto numbers the task. In columns I and K I used data validation to have the user select the priority level and the Yes/No response.

    The rows start on #6.

    I have attached a sample spreadsheet.

    Any help would be greatly appreciated.

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Help on writing a Macro to delete rows with certain criteria

    Give this a try

    Sub abc()
     Const sh1 As String = "To Do List"
     Dim a, b, i As Long, ii As Long, n As Long
     
     With Worksheets(sh1)
        a = .Range("b5").CurrentRegion
     
        ReDim b(1 To UBound(a) - 1, 1 To UBound(a, 2) - 1)
        For i = 2 To UBound(a)
            If UCase(a(i, 10)) <> "YES" Then
                n = n + 1
                For ii = 2 To UBound(a, 2)
                    b(n, ii - 1) = a(i, ii)
                Next
            End If
        Next
        .Range("c6").Resize(UBound(b), UBound(b, 2)) = b
     End With
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    03-05-2011
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Help on writing a Macro to delete rows with certain criteria

    Thank you very much for your help - it worked perfectly!

    Thanks again!

+ 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