Results 1 to 5 of 5

Thread: Get Hidden Rows and Columns

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2009
    Posts
    235

    Get Hidden Rows and Columns

    Hi all,

    I'm working on Windows fom application in vb.net. I want to get the hidden rows and columns in an excel file and make them visable and also delete few of them.

    I have written the below code, but it doesn't do what i wanted to do. Not sure where i'm wrong.
    Code:
     Dim lastRow As Integer
                        Dim lastColumn As Integer
    
                        For lastRow = 1 To rng.Rows.Count
                            For lastColumn = 1 To rng.Columns.Count
     lastColumn = +lastColumn
                            Next
                            lastRow = +lastRow
                        Next
    
    
     For lp = lastColumn To 1 Step -1 'loop through all columns
                            If oWorksheet.Columns(lp).EntireColumn.Hidden = True Then
                                oWorksheet.Columns(lp).EntireColumn.Delete()
                            End If
                        Next
                        For lp = lastRow To 1 Step -1 'loop through all rows
                            If oWorksheet.Rows(lp).EntireRow.Hidden = True Then
                                oWorksheet.Rows(lp).EntireRow.Delete()
                            End If
                        Next
    Thanks in advance.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Get Hidden Rows and Columns

    IF you want to unhide it, why are you deleting them?

    if .Hidden = True means it's been hidden... what would be the logical thing to do to unHide it?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,388

    Re: Get Hidden Rows and Columns

    speaking of Logical things: this is nonsense:
    Code:
                        For lastRow = 1 To rng.Rows.Count
                            For lastColumn = 1 To rng.Columns.Count
     lastColumn = +lastColumn
                            Next
                            lastRow = +lastRow
                        Next
    why the Loop when you already got rng.Rows.Count/rng.Columns.Count?

    and another waste of bits: you don't Need an entirecolumn/entirerow when you Access .columns(x)/.rows(x) as it already is the entire column/row
    Last edited by digitalShaman; Sep 16th, 2015 at 09:11 AM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2009
    Posts
    235

    Re: Get Hidden Rows and Columns

    I want to delete it because, I'm converting the excel later to pdf.

    Te below is the code i'm using and it doesn't work.

    Code:
                             lastColumn = rng.Columns.Count
                             lastRow = rng.Rows.Count
    
                             For lp = lastColumn To 0 Step -1
                             If oWorksheet.Columns(lp).Hidden = True Then
                             oWorksheet.Columns(lp).Delete()
    
                             End If
                             Next
    
                             For lp = lastRow To 0 Step -1
                             If oWorksheet.Rows(lp).Hidden = True Then
                                 oWorksheet.Rows(lp).Delete()
                              End If
    Last edited by vijay2482; Sep 17th, 2015 at 06:33 AM.

  5. #5
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,388

    Re: Get Hidden Rows and Columns

    you Need to be more specific. "it doesn't work" or "it doesn't do what i wanted to do." is not giving any clue on what it does nor what you want it to do.

    some things i could think of are:
    - you are missing the "next" Statement in the second Loop
    - your last Loop Iteration is working on col/row 0 which i do not think is valid for Excel, it should be 1 instead
    - you determin the number of rows and cols based on a range object (rng) but then work on the worksheet, column 1 in the range is not column 1 in the sheet

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width