Consulting

Results 1 to 5 of 5

Thread: Solved: Delete row if default value

  1. #1

    Solved: Delete row if default value

    Hi,

    Im looking to delete a row if the first cell is the defaut value of an excel cell..not sure what the default value of a cell is..i think its blank. So if A1 is default value I want the whole row deleted...

    thanks much

    [VBA]
    Option Explicit

    Sub DeleteRow()
    Dim rRow, Nrow As Long
    Dim oneCell As Range
    rRow = Range("A1").End(xlDown).Row

    For Each oneCell In Range("a1", Cells(rRow, 1)).Cells
    If Left(oneCell.Value, 1) = " " Then
    oneCell.EntireRow.Delete
    End If
    Next
    End Sub

    [/VBA]

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    remove the space from " "

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Deleting rows needs to be done from the bottom up, or all at once

    Two methods

    [VBA]Option Explicit

    Sub DeleteRow()
    Dim rRow As Long
    Dim r As Long
    rRow = Cells(Rows.Count, 1).End(xlUp).Row

    For r = rRow To 1 Step -1
    If Cells(r, 1) = "" Then Rows(r).Delete
    Next
    End Sub

    Sub DeleteRow2()
    Dim LCell As Range
    Set LCell = Cells(Rows.Count, 1).End(xlUp)
    Range(Cells(1, 1), LCell).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    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'

  4. #4
    thanks a bunch!


  5. #5
    MDMACK,

    I know I marked thread solved because it did resolve my initial question...

    I want to use the following to delete rows based on a criteria...basically your second option. I am using a formula in J1:J50 which returns a value of 1...any other value than 1 I want to delete the entire row. I am getting an error of mismatch type I think because it doesnt like the formula in the cell? So basically I want to check J1:J50 for a value of 1..if its not equal to 1 I want to delete the row.

    thanks

    [VBA]
    Option Explicit

    Sub DeleteRow()
    Dim rRow As Long
    Dim r As Long
    rRow = Cells(Rows.Count, 1).End(xlUp).Row

    For r = rRow To 1 Step -1
    If Cells(r, 10) <> 1 Then Rows(r).Delete
    Next
    End Sub
    [/VBA]

Posting Permissions

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