+ Reply to Thread
Results 1 to 5 of 5

Need help please with code to delete rows where a specified cell is blank

Hybrid View

  1. #1
    Registered User
    Join Date
    08-14-2018
    Location
    Ceres, South Africa
    MS-Off Ver
    pro plus 2010
    Posts
    46

    Need help please with code to delete rows where a specified cell is blank

    Hi guys

    I hope someone can help me with this.

    I recently received help from anther forum member to complete a project I was working on, and got stuck.

    Basically... there is various info in a worksheet, that is copied to another worksheet. Since the data that is being copied is filled with formulas, when it is pasted, only the values are pasted.

    Now I have 2 columns that needs to be checked for "blanks" but for some odd reason, the blanks in column "H", even though it shows nothing, excel does not pick it up as a blank.

    The columns I want to be checked for blanks are columns A and H.

    I have searched the forum, and read multiple thread, trying to find a solution, but there is only 1 formula I could find that works for column H, but it takes forever to complete.

    There is approximately 14000 lines that gets copied, but I need to delete the blanks in column H.

    The 2 codes I used is as follows:
    Range("A1:A" & ActiveSheet.UsedRange.Rows.Count).SpecialCells(xlCellTypeVisible).Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
       Selection.EntireRow.Delete
    
     Dim i
        Dim lr As Long
    
        With ThisWorkbook.Sheets("VIP") '**** AMEND THE SHEET NAME TO SUIT ****
            lr = .Cells(Rows.Count, "H").End(xlUp).Row
            For i = lr To 2 Step -1
                If IsError(.Cells(i, "H")) Then
                    .Cells(i, "H").EntireRow.Delete
                ElseIf Cells(i, "H") = "" _
                Or .Cells(i, "H") = 0 Then
                    .Cells(i, "H").EntireRow.Delete
                End If
            Next i
        End With
    Like i said, the formula for column H works, but it takes a very long time to complete. Is there any way to make it run smoother/quicker?

    The sheet that needs to be evaluated is attached as sample.xlsx

    thank you for any input.

    Regards
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,746

    Re: Need help please with code to delete rows where a specified cell is blank

    How about
    Sub DelRows()
    With Sheets("VIP")
       .UsedRange.Value = .UsedRange.Value
       .Range("A:A").SpecialCells(xlBlanks).EntireRow.Delete
       .Range("H:H").SpecialCells(xlBlanks).EntireRow.Delete
    End With
    End Sub

  3. #3
    Registered User
    Join Date
    08-14-2018
    Location
    Ceres, South Africa
    MS-Off Ver
    pro plus 2010
    Posts
    46

    Re: Need help please with code to delete rows where a specified cell is blank

    WOW... thank you

    That did it.

    Wish I knew why it didn't pick up my cells as blanks though.

    Thank you very much for your help sir.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,746

    Re: Need help please with code to delete rows where a specified cell is blank

    Glad to help & thanks for the feedback.

    Where you have a formula that returns "" and you copy/paste as value you will end up with a Null String.
    If you put these 2 formulae in a blank cell
    =ISBLANK(H5)
    =LEN(H5)

    the first returns FALSE & the 2nd returns 0
    Which shows that the cell is not truly blank, however that can be dealt with by using
    .UsedRange.Value = .UsedRange.Value
    This effectively "removes" the Null String

  5. #5
    Registered User
    Join Date
    08-14-2018
    Location
    Ceres, South Africa
    MS-Off Ver
    pro plus 2010
    Posts
    46

    Re: Need help please with code to delete rows where a specified cell is blank

    oh.... I see.

    Thank you once again sir. I really appreciate it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VB Code to delete blank rows
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2017, 03:26 PM
  2. [SOLVED] VBA code to delete rows that are blank
    By cinstanl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2016, 02:35 PM
  3. [SOLVED] VB Code to copy and delete blank rows
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-04-2016, 12:28 AM
  4. Changing code from deleting rows to cut/paste rows into another sheet and delete blank row
    By kmarshall6576 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-18-2013, 01:54 AM
  5. Replies: 1
    Last Post: 05-10-2012, 04:58 PM
  6. Code to delete all blank rows and add totals
    By fusion007 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-24-2011, 04:00 PM
  7. Delete rows if column contains a blank code included
    By v3x0rg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2010, 10:01 AM

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