Results 1 to 10 of 10

Cropping or Deleting useless data

Threaded View

davidfields1985 Cropping or Deleting useless... 03-07-2016, 12:24 PM
Pauleyb Re: Cropping or Deleting... 03-07-2016, 08:39 PM
Philb1 Re: Cropping or Deleting... 03-08-2016, 12:04 AM
FDibbins Re: Cropping or Deleting... 03-08-2016, 12:47 AM
Philb1 Re: Cropping or Deleting... 03-08-2016, 12:54 AM
FDibbins Re: Cropping or Deleting... 03-08-2016, 12:57 AM
FDibbins Re: Cropping or Deleting... 03-08-2016, 01:01 AM
Philb1 Re: Cropping or Deleting... 03-08-2016, 03:00 AM
FDibbins Re: Cropping or Deleting... 03-08-2016, 03:02 AM
Philb1 Re: Cropping or Deleting... 03-08-2016, 03:04 AM
  1. #3
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Cropping or Deleting useless data

    Here's a VBA way of doing it.
    The code as it is now only works with sheet 1. It deletes all the rows that are zero from column A to the last used column. I presumed all the data you want to keep is always at the top of a data block, and when the zero rows start, they are all zero rows until the last row of the block.
    Cheers

    Dropbox link coz the site is still broken
    https://www.dropbox.com/s/mx089pja2v...Rows.xlsb?dl=0

    Option Explicit
    
    Sub DeleteZeroLines()
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
    End With
    
    Dim Ws1 As Worksheet
    Dim rCell As Range
    Dim Top0Row As Long, Bot0Row As Long, OldBot0Row As Long, cColNum As Long
    Dim AWF As Object
    Set Ws1 = ThisWorkbook.Sheets(1)
    Set AWF = Application.WorksheetFunction
    
    On Error Resume Next
    '   Find last used column
        cColNum = Ws1.Cells.Find(what:="*", LookIn:=xlValues, _
            lookat:=xlPart, searchorder:=xlByColumns, searchdirection:=xlPrevious, _
            MatchCase:=False, searchformat:=False).Column
            
    '   Find top row of data
        Top0Row = Ws1.Columns(1).Find(what:="*", LookIn:=xlValues, _
            lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, _
            MatchCase:=False, searchformat:=False).Row
            
    '   Find bottom row of first block of data
        Bot0Row = Ws1.Columns(1).Find(what:="", After:=Ws1.Cells(Top0Row, 1), LookIn:=xlValues, _
            lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, _
            MatchCase:=False, searchformat:=False).Row - 1
            OldBot0Row = Bot0Row
    
    Do ' Start loop
    
        For Each rCell In Ws1.Range(Ws1.Cells(Top0Row, 1), Ws1.Cells(Bot0Row, 1))
            If AWF.Sum(Ws1.Range(Ws1.Cells(rCell.Row, 1), Ws1.Cells(rCell.Row, cColNum))) = 0 Then
            Top0Row = rCell.Row
            Exit For
            End If
        Next rCell
        
        Ws1.Range(Ws1.Cells(rCell.Row, 1), Ws1.Cells(Bot0Row, 1)).EntireRow.Delete
        
    '   Force routine it to continue if a group of data doesn't contain 3 cells in a row containing 0
        If rCell.Row = 0 Then Top0Row = Bot0Row
        
    '   Find top row of next block of data
            Top0Row = Ws1.Columns(1).Find(what:="*", After:=Ws1.Cells(Top0Row, 1), LookIn:=xlValues, _
                lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, _
                MatchCase:=False, searchformat:=False).Row
    
    '   Find bottom used row of next block of data
            Bot0Row = Ws1.Columns(1).Find(what:="", After:=Ws1.Cells(Top0Row, 1), LookIn:=xlValues, _
                lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, _
                MatchCase:=False, searchformat:=False).Row - 1
                
            If Bot0Row > OldBot0Row Then
                OldBot0Row = Bot0Row
            Else: End If
        
    '   Test if find has returned to the top of the worksheet meaning
    '   it's finished the last block of data
        If Bot0Row < OldBot0Row Then GoTo ExitOut
    
    Loop
    
    ExitOut:
    On Error GoTo 0
    With Application
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
        .EnableEvents = True
        .ScreenUpdating = True
    End With
    Exit Sub
    
    End Sub
    Attached Files Attached Files
    Last edited by Philb1; 03-08-2016 at 12:08 AM. Reason: Tried & failed to upload a sample file

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Snagit cropping / trimming
    By magijzel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2015, 07:34 PM
  2. [SOLVED] Cleaning up data for printing & deleting useless spaces
    By PaulLor89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2013, 04:08 PM
  3. cropping text
    By kuder in forum Excel General
    Replies: 3
    Last Post: 10-12-2011, 04:12 PM
  4. cropping an object with VBA
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2010, 12:13 PM
  5. Formulas won't enter into cells in Excel 2000 only as useless data
    By rebelkey in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-09-2006, 08:55 AM
  6. Cell cropping with a Macro or VB
    By Alastair79 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-18-2006, 08:45 AM
  7. Cropping a worksheet
    By gord in forum Excel General
    Replies: 3
    Last Post: 08-23-2005, 05:05 PM

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