+ Reply to Thread
Results 1 to 10 of 10

Delete whole row if column F meets a condition untill last row of data

Hybrid View

  1. #1
    Registered User
    Join Date
    04-09-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    54

    Delete whole row if column F meets a condition untill last row of data

    Hi i would like to seek help on vba to Delete whole row if column F meets a condition untill last row of data


    Just to note that the condition is that if a cell = "" | Null | empty delete that partiular row untill the last row of data .. because when i use countblank() = 0 but the cell seem to be empty like jsut white spaces

    in Column F, each row cell suppose to be consisting a word

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Delete whole row if column F meets a condition untill last row of data

    Hi I am not sure I understood You but check this and give the info is it ok?
    Sub aa()
    Dim lastf As Long
    Dim x As Long
    lastf = Cells(Rows.Count, "F").End(xlUp).Row
    For x = lastf To 1 Step -1
        If IsEmpty(Cells(x, 6)) Then
        Cells(x, 6).EntireRow.Delete
        End If
       Next
    End Sub
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Registered User
    Join Date
    04-09-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Delete whole row if column F meets a condition untill last row of data

    thanks i shall try and get back to you ! Thanks !

  4. #4
    Registered User
    Join Date
    04-09-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Delete whole row if column F meets a condition untill last row of data

    Hi tom , tried your codes , good news is that there is not error msg or anything , however bad news is that the row supposingly to be deleted off is still there haha !

    just to provide more information , this blank cells are resulted in one of my previous codes which i split a long string of message ( that in the message there is no spacing in between words an example of a message like : Hicanihelpuyoutodayis12-03-2012)

    i had use

    'splits Text active cell using ALT+10 char as separator
    Application.ScreenUpdating = False
    Dim splitVals As Variant
    Dim totalVals As Long
    'split every row untill is empty
    Worksheets("sheet2").Activate
    Range("F2").Select
    Do Until IsEmpty(ActiveCell.Value)
    splitVals = Split(ActiveCell.Value, Chr(13))
    totalVals = UBound(splitVals)
    Range(Cells(ActiveCell.Row, ActiveCell.Column + 1), Cells(ActiveCell.Row, ActiveCell.Column + 1 + totalVals)).Value = splitVals
    ActiveCell.Offset(1, 0).Select
    Loop

    so there are empty cells between words ( " hi " , "" , "can" , "" , "help" ...... )

    Hope you understand what i am saying =S i not sure how to relate the problem well but this is my try of explaining my problem =S
    Last edited by andywsw; 04-12-2012 at 03:43 AM.

  5. #5
    Forum Contributor PingPing's Avatar
    Join Date
    02-19-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    158

    Re: Delete whole row if column F meets a condition untill last row of data

    Here's a faster algorithm (uses AutoFilter instead of a Loop):
    Public Sub DeleteRows()
        
        Dim lastRow As Long
        Dim rng As Range
    
        Rows(1).Insert
        Range("F1").Value = "Temp"
        With ActiveSheet
            .UsedRange
            lastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
            Set rng = Range("F1", Cells(lastRow, "F"))
            rng.AutoFilter Field:=1, Criteria1:="="
            rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
            .UsedRange
        End With
    
    End Sub

  6. #6
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Delete whole row if column F meets a condition untill last row of data

    send maybe the sample (excel file)

  7. #7
    Registered User
    Join Date
    04-09-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Delete whole row if column F meets a condition untill last row of data

    BookKeeping.xls

    Here you go a sample data of what i am doing

    Please note the third row consist of blank cells but happens to contain something but i am not sure whats its value is like a space or some value !


    i need to search through all rows of data till the last , deleting whole row like row 3 has

    BTW Please note also that the total table rows varies too , so there are rows similar to row 3 will be in randomly row places or maybe at the last row of all rows too !
    Last edited by andywsw; 04-12-2012 at 04:01 AM.

  8. #8
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Delete whole row if column F meets a condition untill last row of data

    try this then
    Sub aa()
    Dim lastf As Long
    Dim x As Long
    lastf = Cells(Rows.Count, "F").End(xlUp).Row
    For x = lastf To 1 Step -1
        If IsEmpty(Cells(x, 6)) Or Cells(x, 6).Value = Chr(10) Then
        Cells(x, 6).EntireRow.Delete
        End If
       
       Next
    End Sub
    or try to change code from other Poster above (faster one)
    p.s. your empty cells contain chr(10)

  9. #9
    Registered User
    Join Date
    04-09-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Delete whole row if column F meets a condition untill last row of data

    Actually i manage to do it however what i did is that i had selected other columns with cell totally empty and no value and do pings pings methods.
    Which can be one of the methods that i can use ( THANKS pingping ) . However, just to play safe i would like to use column F as the focus as that cells ( that containt some value : "" null or something ) might pop out in another cell if that happens pingping's method wont work accordingly

  10. #10
    Registered User
    Join Date
    04-09-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Delete whole row if column F meets a condition untill last row of data

    GREAT WORKS LIKE A CHARM THANKS TOMMMMMMMM !!! WOOHO

    May the Thanks be with YOU !! =)))



    btw, had up both of you guy's rep ! thanks !!

+ 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