Consulting

Results 1 to 6 of 6

Thread: Macro to delete rows

  1. #1
    VBAX Regular
    Joined
    Apr 2017
    Posts
    13
    Location

    Macro to delete rows

    Hello, I need a macro to delete and entire row and associated row for an id number that doesn't start with 5.

    Attached is an example of what I have and what I need to create.

    Thanks In Advance,
    Keenan
    Attached Files Attached Files

  2. #2
    VBAX Regular
    Joined
    Apr 2017
    Posts
    13
    Location
    Thank you for not helping me!

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Quote Originally Posted by MJKeenan View Post
    Thank you for not helping me!
    helpers here (and on many forums) provide free help and they are not your subordinates or your employees.

    if you need urgent help you should ask for paid services.
    many forums (or members of the forums personally) provide this too.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Regular
    Joined
    Apr 2017
    Posts
    13
    Location
    Thanks :-)

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Merged cells, Error cells, White text: You believe in making things difficult.

    Option Compare Text
    
    
    Sub Test()
        Call Test1
        Call Test2
    End Sub
    
    
    Sub Test1()
        Dim PL As Worksheet
        Dim Rw As Long
        Set PL = Sheets("Price List")
        With PL
        For Rw = 175 To 4 Step -9
            If Left(.Cells(Rw, 4), 1) <> 5 Then
                .Cells(Rw, 4).Resize(9).EntireRow.Delete
            End If
        Next Rw
        End With
    End Sub
    
    
    Sub Test2()
        Dim OF As Worksheet
        Dim Rw As Long
        Set OF = Sheets("Order Form")
        With OF
            For Rw = 67 To 7 Step -1
                If Not Application.IsError(.Cells(Rw, 4)) Then
                    If Left(.Cells(Rw, 4), 1) <> 5 And .Cells(Rw, 4) <> "" And Left(.Cells(Rw, 4), 1) <> "M" Then
                        .Cells(Rw, 2).MergeArea.EntireRow.Delete
                    End If
                End If
            Next Rw
        End With
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Regular
    Joined
    Apr 2017
    Posts
    13
    Location
    Thanks!!!

Posting Permissions

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