Results 1 to 20 of 26

Thread: Solved: Delete Empty cells with condition

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Can you guys help me with this. I have tried to modify this but nothing seems to work.

    Thanks

    I tried to Modify the original code and it works. But for some reason part of my table next to the main one gets deleted.

    Here is the code I got

    [VBA]Public Sub DeleteData()
    Const FORMULA_CHECK As String = "=AND(B7="""",NOT(OR(A7={""Cookies"",""Salt""})))"
    Dim rng As Range
    Dim lastrow As Long
    Dim i As Long

    With ActiveSheet

    .Columns("J").Insert
    .Rows(5).Insert shift:=xlDown

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("J5").Value = "temp"
    .Range("J6").Value = "FALSE"
    Set rng = .Range("A6").Resize(lastrow, 10)
    .Range(rng.FormatConditions(1).AppliesTo.Address).FormatConditions(1).Delet e
    .Range("J7").Resize(lastrow - 2).Formula = FORMULA_CHECK
    rng.AutoFilter Field:=10, Criteria1:="TRUE"
    Set rng = rng.SpecialCells(xlCellTypeVisible)
    rng.Delete shift:=xlUp

    .Columns("J").Delete

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    Set rng = .Range("A6").Resize(lastrow - 1, 9)
    rng.FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)=1"

    rng.FormatConditions(1).Interior.ColorIndex = 15
    End With
    End Sub
    [/VBA]

    Also when I run it more than once then I get an error in this line

    [VBA].Range(rng.FormatConditions(1).AppliesTo.Address).FormatConditions(1).Delet e[/VBA]
    Last edited by fredlo2010; 05-29-2012 at 09:11 PM.
    Feedback is the best way for me to learn


    Follow the Armies

Posting Permissions

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