Here is the problem:
let's say you have 5 rows, and rows 3 and 4 have a #.
Anz_Zeilen then = 5.
Your look goes from 2 to 5.
when Zeile = 3,
the macro deletes row 3.
Now, what WAS row 4 becomes row 3.
the next loop changes Zeile to 4, thus skipping the "CURRENT" row 3.
when Zeile = 5, row 5 is actually blank...

what I would suggest is to go from the bottom up.

use:
For Zeile = Anz_Zeilen to 2 step -1

that way, you won't be skipping any rows.

hope this helps,

Paul




________________________________
From: Thomas Henke <[email protected]>
To: MS EXCEL AND VBA MACROS <[email protected]>
Sent: Wednesday, September 9, 2009 3:56:41 AM
Subject: $$Excel-Macros$$ Problems with Conditional deletion of rows


Dear NG,

I want to delete rows that contain "#". I wrote a small macro for
this, which principally works, but always one row remains; it is
neither the first nor the last row and I have checked the macro
several time, but I don't find any mistake.
Here is the macro:


Dim z As Integer
Dim length As Integer

Anz_Zeilen = Sheets(Quelle).UsedRange.Rows.Count

With Sheets("Bereinigt")

    For Zeile = 2 To Anz_Zeilen

        length = Len(.Cells(Zeile, 1))

        For z = 1 To length

            If Mid(.Cells(Zeile, 1), z, 1) = "#" Then
                .Rows(Zeile).Delete
            End If

        Next z

    Next Zeile

End With

I appreciate any help & thanks in advance

Thomas


--~--~---------~--~----~------------~-------~--~----~
----------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to [email protected]
If you find any spam message in the group, please send an email to:
Ayush Jain  @ [email protected] or
Ashish Jain @ [email protected]
<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 6,500 subscribers worldwide and receive many nice notes about the 
learning and support from the group. Our goal is to have 10,000 subscribers by 
the end of 2009. Let friends and co-workers know they can subscribe to group at 
http://groups.google.com/group/excel-macros/subscribe
-~----------~----~----~----~------~----~------~--~---

Reply via email to