Results 1 to 2 of 2

Loop through a range to hide rows

Threaded View

  1. #1
    Registered User
    Join Date
    10-08-2008
    Location
    Orlando
    Posts
    5

    Loop through a range to hide rows

    I want to loop through a range. If any data exists on the row of the range from Column C over to the last column in use, I want to hide the row.

    I have questions about null and zero values in the cells. Cells can have either in a row of data. I am hiding zero values but I am assigning a zero value via a function for some cells.

    Using code from a post dealing with a similar problem, this is what I came up with.

    (Sorry if I was supposed to put this in tags. I didn't see the tags for the code on this forum.)
    Dim LastRow, LastCol, LastDataRow, R, TotalRows As Long
    Dim WeeklyValues As Range
        
        'Find the last row, column and last cell of the worksheet.
        LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        LastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
        LastDataRow = ActiveSheet.Cells(LastRow - 2)
        
        'Run the loop to determine if there are any values within the specified range.
        'If there are no values in any cell of a row then hide the row.
        ActiveSheet.Range("C4").Resize(LastDataRow, LastCol).Select
            Selection.Name = WeeklyValues
            
            TotalRows = Range("V" & LastDataRow)
                For R = 4 To TotalRows
                    ActiveSheet.Range("C" & R).Resize(, LastCol).Select
                        If Cells(Selection).Value = 0 Then
                            Rows(R).Hidden = True
                        End If
                Next R
    Please offer suggestions for my code.

    Thanks in advance.
    Last edited by Leith Ross; 10-20-2008 at 10:18 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Hide rows with VBA
    By rs56369 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2008, 05:29 PM
  2. Use to Form to Hide Rows
    By jchambers00 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2008, 10:56 AM
  3. Hide Rows based on dropdown selection...
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2008, 04:09 PM
  4. Replies: 1
    Last Post: 06-30-2007, 01:07 AM
  5. Looping through rows in range AND comparing range cells
    By Damask in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-16-2006, 10:30 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