none
Delete code not working RRS feed

  • Question

  • I used this Macro to delete rows, but not able to delete data, Please help me regarding this.

    'Dim r As Range, rows As Long, i As Long
      'Set r = ActiveSheet.Range("B3:B21991")
     ' rows = r.rows.Count
     ' For i = rows To 1 Step (-1)
      '  If WorksheetFunction.CountA(r.rows(i)) = 0 Then r.rows(i).Delete
    '  Next


    End Sub


    Saniv Sharma

    Monday, July 18, 2016 12:57 PM

Answers

All replies

  • Sub Test()
      Dim R As Range, i As Long
      'Get the used range in column B
      Set R = Range("B3", Range("B" & Rows.Count).End(xlUp))
      'From bottom to top
      For i = R.Rows.Count To 1 Step -1
        'If cell is empty delete the entire row
        If IsEmpty(R.Cells(i)) Then R.Rows(i).EntireRow.Delete
      Next
    End Sub

    Monday, July 18, 2016 7:24 PM
  • Thanks a lot Andreas >> Its working for me now

    Saniv Sharma

    Tuesday, July 19, 2016 8:10 AM
  • Andreas !

    If I have serial number in column "A" and other columns are blank. Can we use the same for this .I am not getting the result with this. Please Help? ( ID 5th was blank from Column B to K.

    ID Project   Numbers Task_Name Duration
    2 ABB Project 14   BD 463 days?
    1 Contractual Start Date 0 days
    2 Dependency: ABB Service Desk Available in India 0 days
    3 <New Task> 1 day?
    4 WORK IN PROGRESS DRAFT - SUBJECT TO REVIEW AND APPROVAL 1 day?
    5
    6 Phase 1 - Country Projects - Rollout 463 days?
    7 Project 14 Bangladesh 463 days?
    8 Project 14 - Enablement Part 1 - Discovery & High Level   Design 241 days
    9 Project   kick-off mobilisation meeting 1 day


    Saniv Sharma

    Tuesday, July 19, 2016 11:39 AM