Delete All Rows Except.....

Closed
fawchert - Nov 12, 2008 at 10:32 PM
aquarelle Posts 7140 Registration date Saturday April 7, 2007 Status Moderator Last seen March 25, 2024 - Nov 14, 2008 at 01:51 PM
Hello,

I have a questions that i could not find the answer yet.
I'm also new in macro VBA programming.
The question is, I need to delete all rows in excel except the last row and any rows that have this word: "Blocked".
Anyone with brilliant idea?
Thanks :)

3 responses

helpmeout Posts 6 Registration date Wednesday November 12, 2008 Status Member Last seen May 18, 2009 5
Nov 13, 2008 at 04:29 AM
hey there,

well i will provide you with a link where you will be able to search for what you are willing to do:

http://office.microsoft.com/en-us/excel/results.aspx?qu=delete+some+rows&sc=9&av=O10100&ofcresset=1

hope it will help you
0
aquarelle Posts 7140 Registration date Saturday April 7, 2007 Status Moderator Last seen March 25, 2024 491
Nov 13, 2008 at 11:20 AM
Hi,
Is the word "blocked" always written in the same column ? If it is the case what column ?
See you
0
Thanks for your respond guys..
no, the word "Blocked" was not always in the same column. I'll received this excel file every week from the users but the format was different. Sometimes could be in column L, sometimes could be M.
I just want this column, remove the others.
Thanks
0
aquarelle Posts 7140 Registration date Saturday April 7, 2007 Status Moderator Last seen March 25, 2024 491
Nov 14, 2008 at 01:51 PM
Hello,
Hope this will work according to your demand :

Sub testDelete()

Dim plage As Range
Dim numlig As Integer
Dim numcol As Integer
Dim cpt As Integer
Dim nblig As Integer
Dim nbcol As Integer

Set plage = Range("A65536").End(xlUp).CurrentRegion
nblig = plage.Rows.Count
nbcol = plage.Columns.Count


For numlig = nblig To 1 Step -1
   cpt = 0 

   For numcol = 1 To nbcol
      If plage.Rows(numlig).Columns(numcol) = "Blocked" Then
          cpt = cpt + 1
      End If
   Next numcol

   If cpt = 0 Then
    Rows(numlig).delete
   End If

Next numlig
End Sub



Best regards
0