+ Reply to Thread
Results 1 to 7 of 7

Macro to delete all rows based on one condition

  1. #1
    Registered User
    Join Date
    09-07-2012
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2007
    Posts
    57

    Macro to delete all rows based on one condition

    Hi guys,

    In my spreadsheet I have over 600K rows, and some of them are not required i.e. they are errors.
    They are not all blank, so I cannot use macro for deleting blank rows.

    I would like to use a macro that deletes all rows from the spreadsheet that contain "#VALUE!" in J column. I'd appreciate very much!

    Thanks,
    vemix

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to delete all rows based on one condition

    Does the formula in the cell result in #VALUE or there are no formulae but just #Value in the cell?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Macro to delete all rows based on one condition

    Hi vemix,

    Try this (though initially on a copy of your data as the results cannot be undone if they're wrong):

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    09-07-2012
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Macro to delete all rows based on one condition

    Hi guys,

    Thanks for your posts. The data is simply a text, and not a formula error.

    Trebor76 - I tried your macro, and I believe I need some adjustments there right ? My knowledge to using macros is limited to clicking "Record macro", or sometimes changing sheet names in the macro but that's it. I'd appreciate some more guidance :-)

  5. #5
    Registered User
    Join Date
    04-21-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    51

    Re: Macro to delete all rows based on one condition

    To delete empty rows in a selected range we can use the following macro. The macro here uses the For Next Loop. First the macro counts the rows in a selected range to determine the when the macro should stop. The For Next statement acts as a counter.

    Sub DelEmptyRow()
    Rng = Selection.Rows.Count
    ActiveCell.Offset(0, 0).Select
    Application.ScreenUpdating = False
    For i = 1 To Rng
    If ActiveCell.Value = "" Then 'You can replace "" with 0 to delete rows with 'the value zero
    Selection.EntireRow.Delete
    Else
    ActiveCell.Offset(1, 0).Select
    End If
    Next i
    Application.ScreenUpdating = True
    End Sub

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to delete all rows based on one condition

    Sonu,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Macro to delete all rows based on one condition

    Trebor76 - I tried your macro, and I believe I need some adjustments there right?
    Only to the wstMyTab and the lngStartRow variables I've commented in the code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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