Results 1 to 20 of 63

Thread: Selecting and deleting rows based on criteria

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #17
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,645
    Quote Originally Posted by snb View Post
    I still think this is sufficient for range starting in row 13:

    Sub M_snb()
        For Each sh In Sheets
            sh.UsedRange.Columns(1).Offset(12).SpecialCells(4).EntireRow.Delete
            sh.Rows(11).SpecialCells(4).EntireColumn.Delete
        Next
    End Sub
    i certainly agree with you.

    but when it comes to process third party data it may become hell on earth.

    last week i was asked to consolidate about 500 email attachments. the files contained web imported data and were emailed by a third party on a daily basis for 2 years. the files had 3 rows of headers with merged rows and columns. many third row headers repeated more than once (under different merged areas). some files had blank row(s) at top, some had blank columns at left. column numbers did not match and changed over time.

    if the table structures of the files were the same it would take a few minutes to complete the requirement. i even did not need to write a procedure for that.


    i think this is the similar case for this thread.




    i think i can adopt your code for workbooks with static First Rows.

    user again will select a cell and that cell's row number will be used to offset the used range to selected cell's row.


    maybe (user first clicks YES button in MsgBox and selects a cell from row 13 for all worksheets in the workbook):
    Sub M_snb()
    
    
        Set fRange = Application.InputBox("Please Select the First Row of the Range", "First Row Selection", Type:=8)
        For Each sh In Sheets
            sh.UsedRange.Columns(1).Offset(fRange.Row - 1).SpecialCells(4).EntireRow.Delete
            sh.Rows(fRange.Row - 2).SpecialCells(4).EntireColumn.Delete
            For Each it In Array("NE", "NW", "YH", "EM", "WM", "E", "L", "IL", "OL", "SE", "SW")
                sh.UsedRange.Offset(fRange.Row - 1).Replace it, "=12/0", xlWhole
            Next
            sh.UsedRange.SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
        Next
    
    End Sub
    Last edited by mancubus; 01-27-2014 at 03:27 PM.
    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)

Posting Permissions

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