Results 1 to 8 of 8

For Each loop doesn't take every row into account

Threaded View

  1. #1
    Registered User
    Join Date
    11-29-2010
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    87

    Question For Each loop doesn't take every row into account

    Hi

    I'm working on a macro in which I want it to delete every row in which the value of the cell in column A matches the value of fixed cell "I1".

    Partially my code works, however it doesn't take every cell in the range in to account. It skips every other row.

    Can anyone of you guys pls help me out with this one?

    Greetz,
    Tino

    Code used:

    Sub TESTING()
        Dim myCel As Range
        Columns("A:A").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("A2") = "=RIGHT(B2,3)"
        Range("A2").Select
        Selection.Copy
        Range("A2:A23").Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=True, Transpose:=False
        Application.CutCopyMode = False
        Range("H1") = "=TODAY()"
        Range("I1") = "=""W"" & INT(((RC[-1]-DATE(YEAR(RC[-1]-WEEKDAY(RC[-1]-1)+4),1,3)+WEEKDAY(DATE(YEAR(RC[-1]-WEEKDAY(RC[-1]-1)+4),1,3))+5)/7)-21)"
        Range("I1").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=True, Transpose:=False
        Application.CutCopyMode = False
        For Each myCel In Range("A:A")
            If myCel.Value = Range("$I$1").Value Then
            myCel.Select
            Selection.EntireRow.Delete
            End If
        Next myCel
    
    End Sub
    Attached Files Attached Files
    Last edited by Cutter; 10-15-2012 at 01:13 PM. Reason: Added code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1