+ Reply to Thread
Results 1 to 3 of 3

Dealing with million plus blank rows

Hybrid View

  1. #1
    Registered User
    Join Date
    03-07-2017
    Location
    Texas
    MS-Off Ver
    Office 2016
    Posts
    39

    Dealing with million plus blank rows

    Hello, everyone! I'm having some trouble with a macro that I inherited from my predecessor. Basically, the issue is that, after the macro has successfully completed, it ends up adding the max amount of blank rows possible in Excel (over a million). I'm still a VBA noob, so I kinda feel overwhelmed with the code. Currently, I just have a separate macro that's deleting the rows after the main macro has finished running. It works, but it isn't pretty, since you have to use two macros, just to get the end result that you want. The best solution would just to know how to code the main macro, so it doesn't end up inserting the blank rows. The second best option would be merging the "DeleteBlankRows" macro with the main macro.


    Sub DeleteUnused()
      
    
    Dim myLastRow As Long
    Dim myLastCol As Long
    Dim wks As Worksheet
    Dim dummyRng As Range
    
    
    For Each wks In ActiveWorkbook.Worksheets
      With wks
        myLastRow = 0
        myLastCol = 0
        Set dummyRng = .UsedRange
        On Error Resume Next
        myLastRow = _
          .Cells.Find("*", after:=.Cells(1), _
            LookIn:=xlFormulas, lookat:=xlWhole, _
            searchdirection:=xlPrevious, _
            searchorder:=xlByRows).Row
        myLastCol = _
          .Cells.Find("*", after:=.Cells(1), _
            LookIn:=xlFormulas, lookat:=xlWhole, _
            searchdirection:=xlPrevious, _
            searchorder:=xlByColumns).Column
        On Error GoTo 0
    
        If myLastRow * myLastCol = 0 Then
            .Columns.Delete
        Else
            .Range(.Cells(myLastRow + 1, 1), _
              .Cells(.Rows.Count, 1)).EntireRow.Delete
            .Range(.Cells(1, myLastCol + 1), _
              .Cells(1, .Columns.Count)).EntireColumn.Delete
        End If
      End With
    Next wks
    
    End Sub
    
    '================================
    Sub TestForMergedCells()
    
      Dim AnyMerged As Variant
    
      AnyMerged = ActiveSheet.UsedRange.MergeCells
    
      If AnyMerged = False Then
          MsgBox "no merged"
      ElseIf AnyMerged = True Then
          MsgBox "all merged"
      ElseIf IsNull(AnyMerged) Then
          MsgBox "mixture"
      Else
          MsgBox "never gets here--only 3 options"
      End If
    
    End Sub
    '=====================================
    Last edited by cluelessdood; 11-08-2018 at 11:13 AM.

  2. #2
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Perth Western Australia
    MS-Off Ver
    Office 365
    Posts
    257

    Re: Dealing with million plus blank rows

    Hi

    Would you like to upload the main macro which may be easily modified.

    Cheers

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Dealing with million plus blank rows

    Could you attach a sample with millions of blank rows?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Dealing with blank rows in pivot tables
    By Trebor777 in forum Excel Charting & Pivots
    Replies: 11
    Last Post: 11-30-2016, 11:19 AM
  2. Replies: 5
    Last Post: 02-25-2015, 10:38 AM
  3. Dealing with 6 million rows of data
    By ccastell88 in forum Excel General
    Replies: 5
    Last Post: 12-18-2014, 01:32 AM
  4. Delete duplicate rows with same data in certain columns for million rows
    By amlan009 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-08-2012, 12:53 AM
  5. Thoughts on Working with 1 Million Rows?
    By drew138 in forum Excel General
    Replies: 3
    Last Post: 10-26-2009, 10:49 PM
  6. How do I extend worksheet to 1 million rows?
    By mrmag2000 in forum Excel General
    Replies: 2
    Last Post: 05-20-2009, 08:03 PM
  7. CSV File with over 1 Million Rows
    By vikas.bhandari in forum Excel General
    Replies: 4
    Last Post: 04-23-2007, 05:02 AM

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