Results 1 to 5 of 5

Thread: How to delete hidden rows in Workbook using Macros ?

  1. #1
    Join Date
    Feb 2009
    Posts
    68

    How to delete hidden rows in Workbook using Macros ?

    hello,

    I want to delete some rows in a worksheet that are kept hidden. Is it possible to remove these hidden rows in a workbook using macros ? Can someone provide me the information regarding this ?

    any ideas....

  2. #2
    Join Date
    May 2008
    Posts
    4,345

    Re: How to delete hidden rows in Workbook using Macros ?

    Yes, it's possible to delete rows in a workbook. Here is the macro to do the same -

    Code:
    Sub DeleteHiddenRows_Workbook() 
    
    'This Microsoft Excel Macro will remove hidden rows from 
    'all worksheets in a workbook.
    
    For i = 1 To Worksheets.Count
    If Worksheets(i).Visible Then
    Worksheets(i).Select
    ActiveCell.SpecialCells(xlLastCell).Select
    k = ActiveCell.Row
    For j = 1 To k
    If Rows(j).Hidden Then
    Rows(j).Hidden = False
    Rows(j).Delete
    End If
    Next j
    End If
    Next i
    If Worksheets(1).Visible Then Worksheets(1).Select
    
    End Sub

  3. #3
    Join Date
    May 2008
    Posts
    4,345

    Re: How to delete hidden rows in Workbook using Macros ?

    Note - This macro will delete hidden rows from every worksheet in an entire workbook. However, note that this will only delete one hidden row from a group at once. This means that if you have rows 3-9 hidden on a sheet and rows 45-55 hidden on the same sheet, the last hidden rows (row 9 and row 55) will be deleted on that worksheet. This means that the entire section of rows 3-9 etc. will not be deleted in one pass. Obviously if you are working with workbook that relies heavily on hidden data and hidden rows, this might not be the best macro.

  4. #4
    Join Date
    May 2008
    Posts
    4,831

    Re: How to delete hidden rows in Workbook using Macros ?

    Try this and check whether it works -

    Code:
    Sub deletehidden()
    
    For lp = 1 To 256 'loop through all columns
    If Columns(lp).EntireColumn.Hidden = True Then Columns(lp).EntireColumn.Delete Else
    Next
    
    For lp = 1 To 65536 'loop through all rows
    If Rows(lp).EntireRow.Hidden = True Then Rows(lp).EntireRow.Delete Else
    Next
    End Sub

  5. #5
    Join Date
    Apr 2008
    Posts
    4,088

    Re: How to delete hidden rows in Workbook using Macros ?

    You can remove hidden rows from all the sheets -

    Sub DeleteHiddenRows()
    '
    ' Remove hidden rows from all sheets
    '

    For i = 1 To Worksheets.Count
    If Worksheets(i).Visible Then
    Worksheets(i).Select
    ActiveCell.SpecialCells(xlLastCell).Select
    k = ActiveCell.Row
    For j = 1 To k
    If Rows(j).Hidden Then
    Rows(j).Hidden = False
    Rows(j).Delete
    End If
    Next j
    End If
    Next i
    If Worksheets(1).Visible Then Worksheets(1).Select

    End Sub

Similar Threads

  1. Delete duplicate rows using Macros
    By Dyumani in forum Windows Software
    Replies: 5
    Last Post: 12-10-2011, 11:30 AM
  2. Copying Of Rows and Header In new workbook and E-mail
    By winni in forum Windows Software
    Replies: 3
    Last Post: 04-02-2011, 08:20 AM
  3. Hiding rows in Excel 2007 using macros
    By sam007 in forum Windows Software
    Replies: 3
    Last Post: 16-10-2009, 01:57 PM
  4. Replies: 2
    Last Post: 09-07-2009, 08:57 AM
  5. Delete Macros in MS Word 2007
    By jhon in forum Windows Software
    Replies: 3
    Last Post: 04-04-2009, 12:58 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
  •  
Page generated in 1,726,779,953.36648 seconds with 17 queries