excel range selection in loop not working

aswathy0001

New member
Joined
Nov 29, 2016
Messages
24
Reaction score
0
Points
0
Location
india
Excel Version(s)
2010
Code:
Sub test1()Dim i As Integer
Dim acount
acount = Range("A" & Rows.Count).End(xlUp).Row


For i = 1 To acount
If Range("A:D" & i).Value = "" Then
Range("A:D" & i).Select
Selection.Delete shift:=xlUp
End If
Next i
i = i + 1




End Sub
why this code is not working?
 
Code:
Sub test1()Dim i As Integer
Dim acount
acount = Range("A" & Rows.Count).End(xlUp).Row


For i = 1 To acount
If Range("A" &  i &  ":D" & i).Value = "" Then
Range("A" &  i &  ":D" & i).Select
Selection.Delete shift:=xlUp
End If
Next i
i = i + 1
 
While testing this I got an error with Range("A" & i & ":D" & i).Value = ""
If I gather properly what you want perhaps:
Code:
Sub test2()
Dim i As Integer
Dim acount

acount = Range("A" & Rows.Count).End(xlUp).Row
For i = acount To 1 Step -1
  If Application.CountBlank(Range("A" & i & ":D" & i)) = 4 Then Range("A" & i & ":D" & i).Delete shift:=xlUp
Next i
i = i + 1
End Sub
 
Back
Top