VBA delete empty rows but with ""

JokevdVen

New Member
Joined
Jun 21, 2007
Messages
6
Hello VBA experts,

I need to delete empty rows in a long list with data however the cells are not completely blank but contain "".

I have tried the following code but it isnot working. Anybody who can advise me how to do it??


Sub deleteR()

Sheet10.Activate
Dim r, n As Range
Set n = Range("A2", Range("A6000").End(xlUp))

For Each r In n
If r.Value = "" Then
r.EntireRow.delete
End If
Next r
End Sub


Thanks !

Joke
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
1) Loop backwards when you delete/insert Row(s)
2) If you want to use For Each loop then try
Code:
Sub deleteR()
Dim r, txt As String
Again:
With Sheet10
     For Each r In .Range("a2",.Range("a" & Rows.Count).End(xlUp))
          If r.Value = "" Then
                txt = txt & "," & r.Address(0,0)
                If Len(txt) > 245 Then
                     .Range(Mid$(txt,2)).EntireRow.Delete
                     txt = "" : GoTo Again
                End If
          End If
     Next r
     If Len(txt) Then .Range(Mid$(txt,2)).EntireRow.Delete
End With
End Sub
 
Upvote 0

Krishnakumar

Well-known Member
Joined
Feb 28, 2003
Messages
2,615
Hi,

Code:
Sub DeleteRows()
Dim a, i As Long, w(), j As Long
a = Range("a2", Range("a" & Rows.Count).End(xlUp))
ReDim w(1 To UBound(a, 1), 1 To 1)
For i = 1 To UBound(a, 1)
    If Len(a(i, 1)) > 0 Then
        j = j + 1: w(j, 1) = a(i, 1)
    End If
Next
With Range("a2")
    .CurrentRegion.Resize(, 1).Offset(1).ClearContents
    .Resize(j).Value = w
End With
End Sub

HTH
 
Upvote 0

Forum statistics

Threads
1,186,921
Messages
5,960,575
Members
438,486
Latest member
ncc84330

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top