Consulting

Results 1 to 7 of 7

Thread: Solved: Simple delete entire row

  1. #1
    VBAX Tutor
    Joined
    Mar 2009
    Posts
    227
    Location

    Solved: Simple delete entire row

    I'm trying to delete entire row if cell in Column C is blank, but how do I say that the cell is blank, I tried 'Nothing', 'IsEmpty' but I'm doing it wrong

    this is such an easy one, I cant even figure this out
    any suggestions?
    thanks

    [VBA]
    Sub deleter()
    Dim i As Integer
    Dim cell As Range
    Dim rng As Range
    i = Sheets("Metals").Range("C" & Rows.Count).End(xlUp).Row
    Set rng = Sheets("Metals").Range("C4:C" & i)
    For Each cell In rng
    If cell.Value = xlCellTypeBlanks Then
    cell.EntireRow.Delete
    End If

    Next cell
    End Sub

    [/VBA]

  2. #2
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    try:

    [VBA]
    Sub deleter()
    Dim i, j As Integer

    i = Sheets("Metals").Range("C" & Rows.Count).End(xlUp).Row

    For j = i To 4 Step - 1
    If cells(j, 3).Value = "" Then
    Rows(j).EntireRow.Delete
    End If

    Next j
    End Sub

    [/VBA]

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Something like this. You might want to use rows.count instead of the hard coded number, ie 65536

    [VBA]Option Explicit
    Sub DeleteBlankInColA()
    Dim test As Boolean, x As Long, lastrow As Long, col As Long
    Range("A1").Select
    col = ActiveCell.Column
    lastrow = Cells(65536, col).End(xlUp).Row
    For x = lastrow To 1 Step -1
    test = Cells(x, col).Text Like "[]"
    If test = True Then Cells(x, col).EntireRow.Delete
    Next
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Maybe something like this


    [vba]
    On Error Resume Next
    With Worksheets("sheet1")
    Intersect(.UsedRange, .Columns("C:C")).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End With
    On Error GoTo 0
    [/vba]

    Paul

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Without looping. But this will not delete Row 1
    [VBA]
    Sub Macro1()
    Columns("C:C").AutoFilter Field:=1, Criteria1:="="
    Rows("2:" & Cells.Find("*", searchdirection:=xlPrevious).Row).Delete
    Columns("C:C").AutoFilter
    End Sub

    [/VBA]
    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 Tutor
    Joined
    Mar 2009
    Posts
    227
    Location
    thanks a lot guys

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    or just:
    [VBA]Sub Macro1()
    Columns("J").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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