+ Reply to Thread
Results 1 to 6 of 6

Remove row REF and N/A

  1. #1
    Registered User
    Join Date
    04-26-2005
    Posts
    17

    Remove row REF and N/A

    I found this code to remove the row in case a cell is left blank.


    How can I amend it that it removes the row in case there is a #N/A or
    #REF! exception mode in the cell?


    Thank you.

    Sebastien

    ============================


    Public Sub DeleteRows()
    Dim rng As Range


    Application.ScreenUpdating = False


    On Error Resume Next
    Set rng =
    Worksheets("ExportData").Range*("B1:B1000").SpecialCells(xlCe*llTypeBlanks)


    On Error GoTo 0


    If Not rng Is Nothing Then rng.EntireRow.Delete


    Worksheets("ExportData").Selec*t
    Range("A1").Select


    Application.ScreenUpdating = True


    End Sub

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    I think this will work for you:

    Sub DeleteBlankAndErrRows()
    Dim rng1 As Range

    Application.ScreenUpdating = False

    On Error Resume Next
    Set rng1 = Worksheets("ExportData").Range("B1:B1000").SpecialCells(xlCellTypeBlanks)
    If Err.Number = 0 Then
    rng1.EntireRow.Delete
    End If

    Err.Number = 0
    On Error Resume Next
    Set rng1 = Worksheets("ExportData").Range("B1:B1000").SpecialCells(xlCellTypeFormulas, xlErrors)
    If Err.Number = 0 Then
    rng1.EntireRow.Delete
    End If

    Set rng1 = Nothing

    Application.ScreenUpdating = true

    End Sub


    Does that help?

    Ron

  3. #3
    Registered User
    Join Date
    04-26-2005
    Posts
    17

    Does not work

    It does not react. I put in the formula and ran the macro but nothin happens.

    Could you help me out thanks!

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    I created a worksheet named "ExportData" and ran a constant downs cells B1:B1000. Then I cleared the contents of several cells and entered =na() in a few others. I also entered =A1 in a cell and copied it up one cell, causing the #REF! error.

    After doing that, I ran the DeleteBlankAndErrRows macro. It found all of the errors and blank cells and deleted their rows.

    Am I adequately covering the kinds of information that you have in your worksheet? What issues are you running into?

    Ron

  5. #5
    Registered User
    Join Date
    04-26-2005
    Posts
    17
    It only deletes rows with empty cells but not those with either a #REF! or #N/A






    Sub DeleteBlankAndErrRows()
    Dim rng1 As Range

    Application.ScreenUpdating = False

    On Error Resume Next
    Set rng1 = Worksheets("Data1").Range("A1:AF65536").SpecialCells(xlCellTypeBlanks)
    If Err.Number = 0 Then
    rng1.EntireRow.Delete
    End If

    Err.Number = 0
    On Error Resume Next
    Set rng1 = Worksheets("Data1").Range("A1:AF65536").SpecialCells(xlCellTypeFormulas, xlErrors)
    If Err.Number = 0 Then
    rng1.EntireRow.Delete
    End If

    Set rng1 = Nothing

    Application.ScreenUpdating = True

    End Sub

  6. #6
    Registered User
    Join Date
    04-26-2005
    Posts
    17
    I got it working


    Thank you soooooo much


    Sebastien

+ 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