+ Reply to Thread
Results 1 to 7 of 7

Delete empty rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-10-2013
    Location
    Veendam
    MS-Off Ver
    Excel 2007
    Posts
    100

    Delete empty rows

    Hi all,

    I use the following macro:

    Sub hidden()
    Dim r As Integer, tot As Integer
      tot = Range("A228").CurrentRegion.Rows.Count + 1000 
      For r = 228 To tot
        If Cells(r, 1) = "" And Cells(r, 1) = "" _
          And Cells(r, 17) = "" Then _
          Rows(r).Hidden = True
      Next r
    End Sub
    It is possible that the emty rows be removed instead of hidden?

    Regards,

    Danielle

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Delete empty rows

    Try changing:

    Rows(r).Hidden = True
    to

    Rows(r).EntireRow.Delete
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

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

    Re: Delete empty rows

    It is possible that the empty rows be removed instead of hidden?
    It may or may not, depending on what is in empty cell
    If Cells(r, 1) = ""  repeated twice.

  4. #4
    Forum Contributor
    Join Date
    07-10-2013
    Location
    Veendam
    MS-Off Ver
    Excel 2007
    Posts
    100

    Re: Delete empty rows

    When the row in column 1 and 17 is empty, then the macro must delete the line.

    I have tried this code:

    Sub delete()
      Sheets("TariefDisplay").Select
    Dim r As Integer, tot As Integer
      tot = Range("A228").CurrentRegion.Rows.Count + 1000 'verwijderen tot de aangegeven rijnummer
      For r = 228 To tot
        If Cells(r, 1) = "" And Cells(r, 17) = "" _
          Then _
          Rows(r).EntireRow.Delete
      Next r
    End Sub
    But is not working.

    What's wrong with the macro?

    Regards,

    Danielle

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

    Re: Delete empty rows

    Try looping back ward

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

    Re: Delete empty rows

    You can not use reserved word(delete) to name your sub

    Sub deleteme()
    Dim r As Integer, tot As Integer
    
     With Sheets("TariefDisplay")
    
        tot = .Range("A228").CurrentRegion.Rows.Count + 1000 'verwijderen tot de aangegeven rijnummer
        For r = tot To 228 Step -1
          If .Cells(r, 1) = "" And .Cells(r, 17) = "" _
            Then _
            .Rows(r).delete
        Next r
     End With
    End Sub

  7. #7
    Forum Contributor
    Join Date
    07-10-2013
    Location
    Veendam
    MS-Off Ver
    Excel 2007
    Posts
    100

    Re: Delete empty rows

    Thanks

    This code works:

    Sub deleteme()
    Dim r As Integer, tot As Integer
    
     With Sheets("TariefDisplay")
    
        tot = .Range("A228").CurrentRegion.Rows.Count + 1000 
        For r = tot To 228 Step -1
          If .Cells(r, 1) = "" And .Cells(r, 17) = "" _
            Then _
            .Rows(r).delete
        Next r
     End With
    End Sub

+ 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. Delete rows after first empty row
    By Rose0402 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-09-2013, 04:16 PM
  2. Delete empty rows
    By indhaka in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-03-2012, 09:27 AM
  3. delete duplicate rows, delete empty rows
    By loade in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-03-2012, 05:42 AM
  4. VBA to delete empty rows
    By Borg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-11-2010, 12:15 PM
  5. Autofilter/delete empty rows is deleting non-empty rows!
    By oOarthurOo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2010, 12:31 PM

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