+ Reply to Thread
Results 1 to 7 of 7

Hide rows when two cells are blank

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-16-2014
    Location
    Hyderabad
    MS-Off Ver
    MS Office 2021
    Posts
    347

    Hide rows when two cells are blank

    Hi all!

    I want to hide an entire row, if cell in column B and Column C is blank. I m using the below code but getting an error type Mismatch 13 and highlighting the
    lr = Range("REMARKS1")
    .

    My Data Starts at 190 and ends at 325; hence I am named that range as "Remarks1"

    Column C contains formulas.

    I am using the below code:
    Sub HideBlanks()
    Dim lr As Long, i As Long
    lr = Range("REMARKS1")
    For i = 190 To lr
      ' check B, C, to see if blank
      If Range(Cells(i, "B"), Cells(i, "C")) = "" Then
           Rows(i).Hidden = True 'hide row
        End If
    Next i
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Hide rows when two cells are blank

    you have defined lr as Long but you have set it equal to a range. That is why you get the error

  3. #3
    Forum Contributor
    Join Date
    09-16-2014
    Location
    Hyderabad
    MS-Off Ver
    MS Office 2021
    Posts
    347

    Re: Hide rows when two cells are blank

    Still error persits

    Using
    lr = Range("REMARKS1").Row + Range("REMARKS1").Rows.Count - 1
    With lr as Long, I am getting Type Mis-match and highlighting
    If Range(Cells(i, "B"), Cells(i, "C")) = "" Then
    With lr as Range, I am getting Object Variable or With Block Variable not set and highlighting
    lr = Range("REMARKS1").Row + Range("REMARKS1").Rows.Count - 1

  4. #4
    Forum Contributor
    Join Date
    09-16-2014
    Location
    Hyderabad
    MS-Off Ver
    MS Office 2021
    Posts
    347

    Re: Hide rows when two cells are blank

    I have changed now to
    Dim lr As Range, i As Long
    Still an error satying Run-time error: 91

    Object Variable or With Block Variable not set.

  5. #5
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Hide rows when two cells are blank

    You can use
    lr = Range("REMARKS1").Row + Range("REMARKS1").Rows.Count - 1
    to get the last row in that named range where lr is still defined as long (or integer).

    You cannot use it as a range because For i = .. To... requires 2 integers.

  6. #6
    Forum Contributor
    Join Date
    09-16-2014
    Location
    Hyderabad
    MS-Off Ver
    MS Office 2021
    Posts
    347

    Re: Hide rows when two cells are blank

    Thank Arkadi.

    That helped.

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Hide rows when two cells are blank

    Try this one:

    Sub HideBlanks()
    
    
    For Each rw In Range("Remarks1").Rows
        If Range("B" & rw.Row) = "" And Range("C" & rw.Row) = "" Then Rows(rw.Row).Hidden = True
    Next rw
    
    End Sub
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

+ 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. Hide Rows for First Set of Consecutive Blank Cells in Column
    By pastuslm in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-22-2015, 03:22 PM
  2. Hide Cells with zero values but blank rows should be ignored
    By ckozakos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2011, 06:27 AM
  3. HIDE ZEROS IN CHART - Hide rows of cells that equals zero
    By sweedey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-09-2011, 08:18 PM
  4. Hide all rows where a range of cells are blank
    By a45ward in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-02-2010, 06:29 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