Results 1 to 3 of 3

Thread: excel range selection in loop not working

  1. #1
    Neophyte aswathy0001's Avatar
    Join Date
    Nov 2016
    Location
    india
    Posts
    3
    Articles
    0
    Excel Version
    2010

    Post excel range selection in loop not working



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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?

  2. #2
    Conjurer alansidman's Avatar
    Join Date
    Oct 2018
    Location
    Steamboat Springs
    Posts
    194
    Articles
    0
    Excel Version
    2019
    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

  3. #3
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,620
    Articles
    0
    Excel Version
    365
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •