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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

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
 

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,102
Messages
5,768,102
Members
425,454
Latest member
khoro

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