Consulting

Results 1 to 3 of 3

Thread: Solved: Step Backwards through range

  1. #1

    Solved: Step Backwards through range

    I am trying to step backwards through a range since I am trying to delete rows. Here is my code. i just need it to start at A150 and go through A7. In fact it would be better if the end of the range could be dynamic. Thanks for the help:
    [VBA]With ListBox1
    For i = 0 To .ListCount - 1
    If .Selected(i) Then


    Set r1 = Range("A7:A150")
    For Each c1 In r1
    If c1.Value = .List(i) Then
    c1.Font.Bold = True
    With c1
    c1.EntireRow.Delete
    End With
    End If
    Next c1

    End If
    Next i
    End With[/VBA]
    Last edited by Bob Phillips; 05-04-2012 at 04:32 PM. Reason: Added VBA tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]With ListBox1
    For i = 0 To .ListCount - 1
    If .Selected(i) Then

    lastrow = cell(Rows.Count, "A").End(xlUp).Row

    For ii = lastrow To 7 Step -1
    If Cells(ii, "A").Value = .List(i) Then
    Cells(ii, "A").Font.Bold = True
    Rows(ii).Delete
    End If
    Next i
    End If
    Next i
    End With
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Be careful with XLD's code because it uses Lastrow. Lastrow might be beyond the A150 limit you indicated in the initial post.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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