• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro Deleting entire line although not blank

I used the below code to delete blank lines on my spreadsheets. Most times it works great but for some reason this time even if any row in Column A is populated it is deleting that row??

Code:
Sub DeleteEmptyRowsInActiveSheet()
Dim lngI As Long
  For lngI = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count To 1 Step -1
    If Application.WorksheetFunction.Count(ActiveSheet.Rows(lngI)) = 0 Then
      ActiveSheet.Rows(lngI).Delete
    End If
  Next
End Sub

The Code leading up to this point is as follows:
Code:
Dim lngI As Long
    Cells.Select
    Selection.UnMerge
    Cells.EntireColumn.AutoFit
    Cells.EntireRow.AutoFit
    Rows("1:11").Select
    Range("A11").Activate
    Selection.Delete Shift:=xlUp
    Rows("2:6").Select
    Range("A6").Activate
    Selection.Delete Shift:=xlUp
    Columns("a:a").EntireColumn.Insert
    For lngI = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count To 1 Step -1
    With Cells(lngI, "A")
        If (IsNumeric(Left(Cells(lngI, 2), 4))) Then Range("B" & lngI).Copy Cells(lngI, 1)
    End With
Next

I did read somewhere that the
Code:
ActiveSheet.UsedRange.Row
can be unstable and I'm wondering if somehow, because I am inserting the new Column into the original it's not being considered/read???

Any help would be appreciated.
 
I would be suspicious of using the Count function, rather than Counta.
Count will only register cells with numbers. If you want to include looking for text, use Counta.
 
Back
Top