Results 1 to 3 of 3

Thread: Deleting rows in Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    2

    Deleting rows in Excel

    Hi

    I'm trying to delete rows in excel which meet certain criteria without much success.

    I have a spreadsheet with 13 columns and column F is an indicator which contains either "mortgage" or blank.

    I need to delete all the rows in the spreadsheet that contain nothing in column F. The data will be refreshed on a daily basis so will have a varying number of rows.

    I'm trying to create a macro in Excel 97, that when run, will delete all the rows but my VB knowledge is very limited.

    Any help will be much appreciated.

    Thanks

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    VB Code:
    1. Do until lngLoop>100
    2.     if len(cells(lngLoop,6))=0 then
    3.        cells(lngloop,1).entirerow.delete
    4.     else
    5.         lngloop=lngloop+1
    6.     end if
    7. loop
    8. next
    Something like that. Experiment.
    Please note that this should work in vba (excel), it also does need to be assigned to the right objects which you will need to set up before calling.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    2
    Hi

    Thank you for your reply.

    I had a look on the internet before I received your reply and found the following code:-

    Sub delnonmort2()
    With ActiveSheet.UsedRange
    lRow = Range(Cells(.Row, 1), Cells(.Rows.Count, 1)).Row
    End With
    Range("A1:M" & lRow).AutoFilter Field:=6, Criteria1:=""
    Rows("2:" & lRow).Delete Shift:=xlUp
    Selection.AutoFilter Field:=6
    Selection.AutoFilter
    End Sub

    I've tried running it but I get a run time error 1004 saying "Microsoft Excel cannot insert or delete a column in a list while the Autofilter command is turned on."

    This is the code debug highlights:-
    "Rows("2:" & lRow).Delete Shift:=xlUp"

    Any help please?

    Thanks

    Jules

Posting Permissions

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



Click Here to Expand Forum to Full Width